From 7bde1c5ab0e3eb029d34ce48efb55e6b3f103b59 Mon Sep 17 00:00:00 2001 From: Albert Hopkins Date: Thu, 17 Dec 2015 21:26:47 +0000 Subject: [PATCH] scripts/echo: don't use ANSI escapes if stdout is not a terminal --- scripts/echo | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/scripts/echo b/scripts/echo index acedf43..96bb0c4 100755 --- a/scripts/echo +++ b/scripts/echo @@ -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')