Standard for ANSI Colors in Terminals
The current situation to get colored output from most console commands is a
Some check for the
TERM environment variable, or look for
Windows, or need to be passed a parameter like
That’s why this page tries to create some sort of “standard” which programs should comply to no matter on which platform they are run.
The idea is to have the environment variables
CLICOLOR_FORCE (which are currently
already used for this exact reason on some UNIX systems). When set, the following rules
CLICOLOR != 0
- ANSI colors are supported and should be used when the program isn’t piped.
CLICOLOR == 0
- Don’t output ANSI color escape codes.
CLICOLOR_FORCE != 0
- ANSI colors should be enabled no matter what.
How to Implement
If you want to check in your program if ANSI colors are supported, it should look like this Python code example:
To get an idea what colors you can use, run the following Python script:
Which should print:
To reset attributes: \x1b[0m \x1b[1;30m \x1b[0;30m \x1b[1;30;40m \x1b[1;31m \x1b[0;31m \x1b[1;31;41m \x1b[1;32m \x1b[0;32m \x1b[1;32;42m \x1b[1;33m \x1b[0;33m \x1b[1;33;43m \x1b[1;34m \x1b[0;34m \x1b[1;34;44m \x1b[1;35m \x1b[0;35m \x1b[1;35;45m \x1b[1;36m \x1b[0;36m \x1b[1;36;46m \x1b[1;37m \x1b[0;37m \x1b[1;37;47m
Also see the ISO 6429 (ANSI) color sequences.
This is a list of bug reports on the progress of supporting
- clang compiler
- GCC compiler
- Jenkins ANSI color plugin
- Rust compiler
- supports-color package
- GitLab CI
The following bug reports have been resolved: