Only output in color when stdout is a TTY

This commit is contained in:
Ross MacArthur
2020-07-24 17:16:50 +02:00
parent 73ec19248f
commit 1a0a58bc60
+3 -1
View File
@@ -78,6 +78,8 @@ named_processes = map(lambda package: package if package.find(":") != len(packag
header_size = args.tag_width + 1 + 3 + 1 # space, level, space
stdout_isatty = sys.stdout.isatty()
width = -1
try:
# Get the current terminal width
@@ -97,7 +99,7 @@ def termcolor(fg=None, bg=None):
return '\033[%sm' % ';'.join(codes) if codes else ''
def colorize(message, fg=None, bg=None):
return termcolor(fg, bg) + message + RESET
return termcolor(fg, bg) + message + RESET if stdout_isatty else message
def indent_wrap(message):
if width == -1: