You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
LSI should not be inserting terminal control codes (i.e. ANSI color codes) unless it is printing to a TTY. When stdout is redirected (i.e. piping to grep, awk, etc, or to a file), then LSI should not insert terminal control codes in its output.
Background info about terminal control codes / ANSI escape sequences:
Some commands that demonstate current LSI behavior:
# display in terminal the fourth column of every EC2 instance returned by this LSI query
$ lsi [query filter] | awk '{ print $4 }'
# redirect stdout of previous command to a file
$ lsi [query filter] | awk '{ print $4 }' > foo.txt
# terminal control codes appear in stdout file contents
$ vim foo.txt
# terminal control codes are included in file contents but aren't displayed when printed to terminal
$ cat foo.txt
We want to emulate grep's --color=auto option, which is smart about when to inject terminal control codes in the output:
# ANSI control codes are evaluated and output is colored when stdout is a terminal
$ echo 'hello world!' | grep --color=auto hello
# ANSI control codes are not included in output sequence when stdout is redirected
$ echo 'hello world!' | grep --color=auto hello > hello.txt
$ vim hello.txt
Suggestion: Instead of unconditionally formatting LSI output with ANSI color codes, we can use the following to check whether stdout is a TTY before doing so:
sys.stdout.isatty()
sys.stderr.isatty()
The text was updated successfully, but these errors were encountered:
LSI should not be inserting terminal control codes (i.e. ANSI color codes) unless it is printing to a TTY. When stdout is redirected (i.e. piping to grep, awk, etc, or to a file), then LSI should not insert terminal control codes in its output.
Background info about terminal control codes / ANSI escape sequences:
Some commands that demonstate current LSI behavior:
We want to emulate grep's
--color=auto
option, which is smart about when to inject terminal control codes in the output:Suggestion: Instead of unconditionally formatting LSI output with ANSI color codes, we can use the following to check whether stdout is a TTY before doing so:
sys.stdout.isatty()
sys.stderr.isatty()
The text was updated successfully, but these errors were encountered: