FORCE_COLOR

An increasing number of command-line software programs support the NO_COLOR environment variable. While many developers and users appreciate the plain output this provides, there should likewise be a way to force color to be enabled in cases where it might otherwise become turned off, like piping the output to a non-interactive terminal. The methods to enable colored text output vary across software, and some don't offer an option at all.

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.

By adopting this standard, users who want colored text output, even in situations like piping or CI environments can simply export FORCE_COLOR=1 to their environment. This will automatically enable color by default in all software that follows the standard.

If your software supports NO_COLOR but doesn't offer a direct way to force enabling color, please consider offering the FORCE_COLOR option. If you decide to, please implement this standard to make it easy for your users to enable color and then add your software to this list by submitting a pull request.

This site is a work in progress and may not be fully complete or accurate. Please feel free to contribute 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

Color software supporting FORCE_COLOR to force enable color support

Software Description Date / Version Supported
node JavaScript runtime
Python Python programming language 2024-10-07 / 3.13
Nox Flexible test automation for Python 2022-01-07 / 2022.1.7
npm Package manager for JavaScript
jest JavaScript testing framework
pytest Python testing framework 2020-07-28 / 6.0.0
turbo Toolchain for frontend development in Rust 2022-04-07 / v1.2.0
Fork me on GitHub!