|
@@ -1,3 +1,6 @@
|
|
|
+import sys
|
|
|
+import os
|
|
|
+
|
|
|
def colors(state):
|
|
|
color = ''
|
|
|
|
|
@@ -21,8 +24,30 @@ def colors(state):
|
|
|
|
|
|
return color
|
|
|
|
|
|
+def supports_color():
|
|
|
+ """
|
|
|
+ from https://github.com/django/django/blob/master/django/core/management/color.py
|
|
|
+ Return True if the running system's terminal supports color,
|
|
|
+ and False otherwise.
|
|
|
+ """
|
|
|
+
|
|
|
+ plat = sys.platform
|
|
|
+ supported_platform = plat != 'Pocket PC' and (plat != 'win32' or 'ANSICON' in os.environ)
|
|
|
+
|
|
|
+ # isatty is not always implemented, #6223.
|
|
|
+ is_a_tty = hasattr(sys.stdout, 'isatty') and sys.stdout.isatty()
|
|
|
+ if not supported_platform or not is_a_tty:
|
|
|
+ return False
|
|
|
+ return True
|
|
|
+
|
|
|
def log(string, color):
|
|
|
- print('\033[1m' + colors(color) + string + colors("ENDC"))
|
|
|
+ if not supports_color():
|
|
|
+ print(string)
|
|
|
+ else:
|
|
|
+ print('\033[1m' + colors(color) + string + colors("ENDC"))
|
|
|
|
|
|
def seperator(color):
|
|
|
- print('\033[1m' + colors(color) + ("-" * 50) + colors("ENDC"))
|
|
|
+ if not supports_color():
|
|
|
+ print("-" * 50)
|
|
|
+ else:
|
|
|
+ print('\033[1m' + colors(color) + ("-" * 50) + colors("ENDC"))
|