We should improve on our ability to correctly detect color capabilities on the console. Many times, build logs in CI environments and similar cases are hard to read due to ANSI codes being written to a console that did not have color capabilities, and this could have been detected.
In the bash scripts, logic like the following can be used:
- If the tput command does not exist, fall back to checking TERM.
- If tput colors returns 8, 16, or 256, the terminal supports at least that many colors.
- The TERM var: the terminal supports 256 colors if TERM contains values xterm-256color, screen-256color, or generally any value containing 256 probably indicates color support.
- Check the value of the COLORTERM environment variable; if truecolor or 24bit, then you have 24-bit RGB capability (this should apply to Linux, Mac OS X, and Windows).
On Windows, COLORTERM is also usually supported in terminals supporting 24-bit RGB; presence of this env var may be sufficient to enable color. The TERM environment variable is also often supported.