Add support for the NO_COLOR environment variable
authorAaron Ballman <aaron@aaronballman.com>
Wed, 7 Jun 2023 15:53:08 +0000 (11:53 -0400)
committerAaron Ballman <aaron@aaronballman.com>
Wed, 7 Jun 2023 15:55:06 +0000 (11:55 -0400)
commitda0a7d5cfb0c65bcb54a1ba5ed6c93bb906648e4
tree8b7c0d55ab3e9003f7db6fcfb8644c2b326dac3f
parent774b33632998591a6714948da62fcf39126b9ee4
Add support for the NO_COLOR environment variable

Clang currently supports disabling color diagnostic output via
-fno-color-diagnostics. However, there is a somewhat long-standing push
to support use of an environment variable to override color output so
that users can set up their terminal such that most color output is
disabled (largely for accessibility reasons).

There are two competing de facto standards to accomplish this:
  NO_COLOR (https://no-color.org/) and
  CLICOLOR/CLICOLOR_FORCE (http://bixense.com/clicolors/).

This patch adds support for NO_COLOR as that appears to be the more
commonly supported feature, at least when comparing issues and pull
requests:
https://github.com/search?q=NO_COLOR&type=issues (2.2k issues, 35k pull requests)
https://github.com/search?q=CLICOLOR&type=issues (1k issues, 3k pull requests)

It's also the more straightforward and thoroughly-specified of the two
options. If NO_COLOR is present as an environment variable (regardless
of value), color output is suppressed unless the command line specifies
use of color output (command line takes precedence over the environment
variable).

Differential Revision: https://reviews.llvm.org/D152285
clang/docs/ReleaseNotes.rst
clang/docs/UsersManual.rst
clang/lib/Frontend/CompilerInvocation.cpp
clang/test/Driver/no-color.c [new file with mode: 0644]