Messages in this thread | | | Date | Mon, 4 Jul 2016 05:24:17 -0700 | From | Josh Triplett <> | Subject | Re: checkkconfigsymbols.py: add --no-color option |
| |
On Mon, Jul 04, 2016 at 06:39:30PM +1000, Andrew Donnellan wrote: > Add a new option, --no-color, to get rid of ANSI colour escape codes in the > output. Useful if redirecting output to a file or piping to another script. > > (It should really be --no-colour, but I'll accept US spelling in the name > of consistency with existing usage in the code comments...) > > Signed-off-by: Andrew Donnellan <andrew.donnellan@au1.ibm.com> > Acked-by: Valentin Rothberg <valentinrothberg@gmail.com>
Rather than requiring an explicit option, how about detecting whether stdout is a TTY and automatically suppressing color? You could check "os.isatty(1)" in main(), and set a global "color = False". That would automatically handle the cases of redirecting to a file or piping to another script, without requiring the user to pass --no-color.
- Josh Triplett
| |