scripts/echo: don't use ANSI escapes if stdout is not a terminal
This commit is contained in:
parent
e867f3cf2e
commit
7bde1c5ab0
16
scripts/echo
16
scripts/echo
|
@ -2,12 +2,20 @@
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
|
TTY = sys.stdout.isatty()
|
||||||
|
|
||||||
write = sys.stdout.write
|
write = sys.stdout.write
|
||||||
|
|
||||||
write('\n')
|
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(' '.join(sys.argv[1:]))
|
||||||
write('\x1b[') # escape, left-bracket
|
|
||||||
write('0m') # reset
|
if TTY:
|
||||||
|
write('\x1b[') # escape, left-bracket
|
||||||
|
write('0m') # reset
|
||||||
|
|
||||||
write('\n')
|
write('\n')
|
||||||
|
|
Loading…
Reference in New Issue