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
+4 -2
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:
@@ -249,7 +251,7 @@ def parse_start_proc(line):
return line_package, '', line_pid, line_uid, '' return line_package, '', line_pid, line_uid, ''
return None return None
def tag_in_tags_regex(tag, tags): def tag_in_tags_regex(tag, tags):
return any(re.match(r'^' + t + r'$', tag) for t in map(str.strip, tags)) return any(re.match(r'^' + t + r'$', tag) for t in map(str.strip, tags))
ps_command = base_adb_command + ['shell', 'ps'] ps_command = base_adb_command + ['shell', 'ps']