-
Notifications
You must be signed in to change notification settings - Fork 61
/
Copy pathcolors.py
45 lines (30 loc) · 1.1 KB
/
colors.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
from colorama import Fore, Back, Style
import sys
class Color:
@staticmethod
def is_atty():
if hasattr(sys.stderr, 'isatty') and not sys.stderr.isatty():
return False
if hasattr(sys.stdout, 'isatty') and not sys.stdout.isatty():
return False
return True
@staticmethod
def error(text):
text = str(text)
return Back.RED + text + Style.RESET_ALL if Color.is_atty() else text
@staticmethod
def control(text):
text = '\n<<< ' + str(text) + ' >>>\n\r'
return Fore.YELLOW + text + Style.RESET_ALL if Color.is_atty() else text
@staticmethod
def control_without_arrows(text):
text = str(text)
return Fore.YELLOW + text + Style.RESET_ALL if Color.is_atty() else text
@staticmethod
def warning(text):
text = '\n\n<<< Warning: ' + str(text) + ' >>>\n'
return Back.YELLOW + text + Style.RESET_ALL if Color.is_atty() else text
@staticmethod
def success(text):
text = str(text)
return Back.GREEN + text + Style.RESET_ALL if Color.is_atty() else text