Merge pull request #163 from rossmacarthur/ft/only-color-a-tty

Only output in color when stdout is a TTY
This commit is contained in:
Jake Wharton
2020-11-20 10:26:27 -05:00
committed by GitHub
+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 header_size = args.tag_width + 1 + 3 + 1 # space, level, space
stdout_isatty = sys.stdout.isatty()
width = -1 width = -1
try: try:
# Get the current terminal width # Get the current terminal width
@@ -97,7 +99,7 @@ def termcolor(fg=None, bg=None):
return '\033[%sm' % ';'.join(codes) if codes else '' return '\033[%sm' % ';'.join(codes) if codes else ''
def colorize(message, fg=None, bg=None): 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): def indent_wrap(message):
if width == -1: if width == -1: