scripts/echo: don't use ANSI escapes if stdout is not a terminal

This commit is contained in:
Albert Hopkins 2015-12-17 21:26:47 +00:00
parent e867f3cf2e
commit 7bde1c5ab0
1 changed files with 12 additions and 4 deletions

View File

@ -2,12 +2,20 @@
import sys
TTY = sys.stdout.isatty()
write = sys.stdout.write
write('\n')
write('\x1b[') # escape, left-bracket
write('1;31m') # bold red
if TTY:
write('\x1b[') # escape, left-bracket
write('1;31m') # bold red
write(' '.join(sys.argv[1:]))
write('\x1b[') # escape, left-bracket
write('0m') # reset
if TTY:
write('\x1b[') # escape, left-bracket
write('0m') # reset
write('\n')