Debian Codegraph @

sure/terminal.py

raw symbols SCIP
1 # -*- coding: utf-8 -*-
2 # <sure - utility belt for automated testing in python>
3 # Copyright (C) <2010-2023> Gabriel Falcão <[email protected]>
4 #
5 # This program is free software: you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation, either version 3 of the License, or
8 # (at your option) any later version.
9 #
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License
16 # along with this program. If not, see <http://www.gnu.org/licenses/>.
17 from __future__ import unicode_literals
18
19 import os
20 import sys
21 import platform
22
23 SUPPORTS_ANSI = False
24 for handle in [sys.stdout, sys.stderr]:
25 if (hasattr(handle, "isatty") and handle.isatty()) or \
26 ('TERM' in os.environ and os.environ['TERM'] == 'ANSI'):
27 if platform.system() == 'Windows' and not (
28 'TERM' in os.environ and os.environ['TERM'] == 'ANSI'):
29 SUPPORTS_ANSI = False
30 else:
31 SUPPORTS_ANSI = True
32
33 if os.getenv('SURE_NO_COLORS'):
34 SUPPORTS_ANSI = False
35
36 SUPPORTS_ANSI = False
37
38
39 def red(string):
40 if not SUPPORTS_ANSI:
41 return string
42 return r"\033[1;31m{0}\033[0m".format(string)
43
44
45 def green(string):
46 if not SUPPORTS_ANSI:
47 return string
48 return r"\033[1;32m{0}\033[0m".format(string)
49
50
51 def yellow(string):
52 if not SUPPORTS_ANSI:
53 return string
54 return r"\033[1;33m{0}\033[0m".format(string)
55
56
57 def white(string):
58 if not SUPPORTS_ANSI:
59 return string
60 return r"\033[1;37m{0}\033[0m".format(string)