back

by emptybits·8y ago·view on hn ↗
This is not a general solution as the author wants, but when I know my own utilities are going to be redirected or piped and I don't want ANSI/colour sequences captured then I've wrapped the ANSI sequences in logic like this: (Python example)

`if sys.stdout.isatty(): ...`

I recognize TTY != ANSI in some cases. And sometimes you actually want control sequences captured or redirected. So this is far from perfect but it might be good enough for some.

Such a check ports across systems well and doesn't rely on a new environment variable.