Tech News
← Back to articles

No_color: Disabling ANSI color output by default

read original related products more articles

NO_COLOR

An increasing number of command-line software programs output text with ANSI color escape codes by default. While some developers and users obviously prefer seeing these colors, some users don’t. Unfortunately, every new piece of software seems to have a different way of disabling colored text output and some software has no way at all.

Accepting the futility of trying to reverse this trend, an informal standard was proposed in 2017:

Command-line software which adds ANSI color to its output by default should check for a NO_COLOR environment variable that, when present and not an empty string (regardless of its value), prevents the addition of ANSI color.

By adopting this standard, users that prefer to have plain, non-colored text output can export NO_COLOR=1 to their shell’s environment and automatically disable color by default in all supported software.

If your software outputs color by default, please consider not doing so. If you insist, please implement this standard to make it easy for your users to disable color and then add your software to this list by submitting a pull request.

If your software does not output color by default, you do not need to bother with this standard.

Example Implementation

#include #include #include int main(int argc, char *argv[]) { char *no_color = getenv("NO_COLOR"); bool color = true; if (no_color != NULL && no_color[0] != '\0') color = false; /* do getopt(3) and/or config-file parsing to possibly turn color back on */ ... }

Frequently Asked Questions

... continue reading