A recent regression was introduced via #1382 which broke detection on various conditions.
For example, on my MacOS host, only stdout and stdin report True on isatty() while stderr reports False, even if in reality there is no problem with sending ANSI to stderr.
Probably we should rely solely on stdout for the test or to assure that we respect it for each tty.
This issue is not happening with lots of people because only few of them use a method to colorize stderr, which apparently is what has a side-effect of marking it as a non tty.
Example of zsh snippet from ~/.zshrc that does this:
export STDERRED_ESC_CODE="$fg[red]"
if [[ "$STDERR_COLORIZE" != $$ ]]; then
if (( $+commands[colorize] )); then
exec 2>>(colorize $fg[yellow] $reset_color > /dev/tty &)
else
exec 2>>(while read line; do
print ${fg[yellow]}$line$reset_color > /dev/tty; print -n $'\0'; done &)
fi
export STDERR_COLORIZE=$$
fi
Once this runs you no longer gave a tty-enabled stderr.
Vast majority of CLI tools I know are using sys.stdout.isatty(), the only other exception I know is mypy. https://bixense.com/clicolors/ seems to support that approach too.
Regarding the never-ending struggle to control ANSI on/off behavior where each tool invented its own implementation and variables to configure behavior, it seems that someone realized that maybe is time to do something about it https://no-color.org/ :)
A recent regression was introduced via #1382 which broke detection on various conditions.
For example, on my MacOS host, only
stdoutandstdinreport True onisatty()whilestderrreports False, even if in reality there is no problem with sending ANSI to stderr.Probably we should rely solely on
stdoutfor the test or to assure that we respect it for each tty.This issue is not happening with lots of people because only few of them use a method to colorize stderr, which apparently is what has a side-effect of marking it as a non tty.
Example of zsh snippet from
~/.zshrcthat does this:Once this runs you no longer gave a tty-enabled stderr.
Vast majority of CLI tools I know are using
sys.stdout.isatty(), the only other exception I know ismypy. https://bixense.com/clicolors/ seems to support that approach too.Regarding the never-ending struggle to control ANSI on/off behavior where each tool invented its own implementation and variables to configure behavior, it seems that someone realized that maybe is time to do something about it https://no-color.org/ :)