@cks I guess checking $TERM (where "dumb" means no ANSI) and if stdout/stderr is a TTY should be enough?
At least that way pipes/file-redirects doesn't puts a bunch of ANSI even when running in a terminal. And TERM=dumb allows very basic terminals (or even non-terminals) to still work.