It would be good to have one variable for tty console output, and another variable for the case where stdout is not a tty.
Ideally I think the default behaviour should be to strip ansi escape sequences when stdout out is not a tty - I've seen this as the default in other programs (i.e. hledger, git diff) and it tends to work well for typical workflows.
As it is, we have tty detection linked to the NOCOLOR environment variable, via this code: > bin/isolated-functions.sh:case "${NOCOLOR:-false}" in > bin/isolated-functions.sh- yes|true) > bin/isolated-functions.sh- __unset_colors > bin/isolated-functions.sh- ;; > lib/_emerge/actions.py- elif settings.get('TERM') == 'dumb' or \ > lib/_emerge/actions.py: not sys.stdout.isatty(): > lib/_emerge/actions.py- portage.output.havecolor = 0 > lib/_emerge/actions.py- settings["NOCOLOR"] = "true" > lib/_emerge/actions.py- settings.backup_changes("NOCOLOR") > eclass/cargo.eclass: $([[ "${NOCOLOR}" = true || "${NOCOLOR}" = yes ]] && echo "color = 'never'") > eclass/cargo.eclass: [[ "${NOCOLOR}" = true || "${NOCOLOR}" = yes ]] && export CARGO_TERM_COLOR=never > eclass/cmake-utils.eclass: [[ "${NOCOLOR}" = true || "${NOCOLOR}" = yes ]] && echo 'SET (CMAKE_COLOR_MAKEFILE OFF CACHE BOOL "pretty colors during make" FORCE)' >> "${common_config}" > eclass/cmake.eclass: if [[ "${NOCOLOR}" = true || "${NOCOLOR}" = yes ]]; then > eclass/ruby-ng.eclass:# which also respects TEST_VERBOSE and NOCOLOR environment variables. > eclass/ruby-ng.eclass: case ${NOCOLOR} in > eclass/ruby-ng.eclass:# which also respects TEST_VERBOSE and NOCOLOR environment variables. > eclass/ruby-ng.eclass: case ${NOCOLOR} in > eclass/ruby-ng.eclass:# This also respects TEST_VERBOSE and NOCOLOR environment variables. > eclass/ruby-ng.eclass: case ${NOCOLOR} in
(Worth noting that NO_COLOR with the underscore seems to be a new standard being converged on: https://no-color.org)