Skip to content

Commit 045b2e7

Browse files
committed
do not use colors if not supported
1 parent 681e499 commit 045b2e7

1 file changed

Lines changed: 15 additions & 1 deletion

File tree

python/code/wypp/ansi.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import re
2+
import sys
3+
import os
24

35
RESET = "\u001b[0;0m"
46
BOLD = "\u001b[1m"
@@ -21,8 +23,20 @@
2123
YELLOW = "\u001b[1;33m"
2224
WHITE = "\u001b[1;37m"
2325

26+
def useColors():
27+
if "NO_COLOR" in os.environ:
28+
return False
29+
if not sys.stdout.isatty():
30+
return False
31+
if os.environ.get("TERM") == "dumb":
32+
return False
33+
return True
34+
2435
def color(s, color):
25-
return color + s + RESET
36+
if useColors():
37+
return color + s + RESET
38+
else:
39+
return s
2640

2741
def green(s):
2842
return color(s, GREEN + BOLD)

0 commit comments

Comments
 (0)