FORCE_COLOR
Many command-line programs support the NO_COLOR
environmental variable. While plain output is fine, users also find they need a way to force color on. In particular, cases where color often forces itself off like piping output. Up until now, the methods to force colored text output have varied by program. Many do not even provide such an option.
To address the desire for a consistent method to force enable color support, an informal standard was proposed in 2023:
Command-line software which outputs colored text should check for a
FORCE_COLOR
environment variable. When this variable is present and not an empty string (regardless of its value), it should force the addition of ANSI color.
This standard allows users to enable color in any context. Add FORCE_COLOR=1
to your environment, and color is enabled in all software supporting the standard.
If your software supports NO_COLOR
but cannot force color, consider offering the FORCE_COLOR
option. If your software already offers a method to force colored output, consider additionally supporting FORCE_COLOR
. If you do add FORCE_COLOR
support, please add your software to this list by submitting a pull request.
Additionally, please feel free to contribute to the standard by submitting a pull request.
Example Implementation
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
int
main(int argc, char *argv[])
{
char *no_color = getenv("NO_COLOR");
char *force_color = getenv("FORCE_COLOR");
bool color = true;
if (no_color != NULL && no_color[0] != '\0')
color = false;
/* do getopt(3) and/or config-file parsing */
if (force_color != NULL && force_color[0] != '\0')
color = true;
...
}
Frequently Asked Questions
Why would I want to force enable color?
Some users prefer to have color enabled. Certain actions like piping output through less
, grep
or tee
will disable color output. This can be frustrating for users who want to see color output in these situations.
Other examples include CI environments which may disable color output by default or may be detected as a non-interactive terminal causing color to be disabled.
Why not just use --color
or -c
?
Many software programs already use --color
or -c
to enable color output. This is a great option to have, but it's not always possible to use. For example, if you're internally piping output to another program, you can't externally use --color
or -c
to enable color output. In these cases, you can use FORCE_COLOR
to force enable color output.
Color libraries supporting FORCE_COLOR
to force enable color support
Library | Description | Date / Version Supported |
---|---|---|
ansis | JavaScript library to colorize terminal with ANSI colors & styles | 2024-04-15 / 3.1.1 |
chalk | Color library for JavaScript | 2015-02-23 / 1.0.0 |
supports-color | JavaScript library to detect terminal color support | 2015-07-15 / 3.0.0 |
colorette | JavaScript library to color text | 2018-07-13 / 1.0.0 |
rich | Python library to display rich text | 2022-10-02 / 12.6.0 |
termcolor | Python library for ANSI color formatting in the terminal | 2022-10-30 / 2.1.0 |
Warna | Terminal text styling library for Lua | 2024-02-11 / 0.1.0 |
Software supporting FORCE_COLOR
to force enable color support
Software | Description | Date / Version Supported |
---|---|---|
node | JavaScript runtime | |
Deno | JavaScript, TypeScript, and WebAssembly runtime | 2025-03-14 / 2.2.4 |
Python | Python programming language | 2024-10-07 / 3.13 |
NVIDIA Legate | NVIDIA's scalable array computing framework | 2025-03-17 / 25.03 |
jest | JavaScript testing framework | |
Julia | Julia programming language | 2025-10-08 / 1.12.0 |
Nox | Flexible test automation for Python | 2022-01-07 / 2022.1.7 |
npm | Package manager for JavaScript | |
pytest | Python testing framework | 2020-07-28 / 6.0.0 |
Sphinx | Documentation generator | 2022-03-28 / 4.5.0 |
turbo | Toolchain for frontend development in Rust | 2022-04-07 / v1.2.0 |
uv | Python package and project manager | 2024-06-06 / 0.2.7 |