Enable or disable colored output according to CLICOLOR(_FORCE)


#1

I suggest using the environment variables CLICOLOR and CLICOLOR_FORCE for enabling colors. CLICOLOR=0 would be --color=never and CLICOLOR_FORCE=1 --color=always.

Why environment variables when there is already a command line switch? When working with build systems, editors or continuous integration servers output almost always gets piped or buffered, so a switch to force colored output is needed. When we agree upon a standard for this, the only thing one would need to do in such a situation is to define CLICOLOR_FORCE=1. I’ve also created a page with a summary: http://bixense.com/clicolors/ Please tell me what you think :slight_smile:

Btw: CMake (used by LLVM) already respects this environment variable to color the Make output.

Corresponding PR: https://github.com/rust-lang/rust/pull/27867


Introducing Colored: the most simple way to add colors in your term!
#2

Yes, please provide some simple global means to turn off color on the command line. I don’t mind whether it’s an environment variable or some configuration file in the home directory.

IMHO it is not a good idea to output colored text when the background color is under the control of the user, it can make the text hard and/or unpleasant to read.

As a workaround I currently use a wrapper script around cargo that deletes the TERM environment variable, but that’s not really a nice solution.

The --color command line option on cargo is hard to use in a wrapper script, because it needs to come after the subcommand.