Uh oh!
There was an error while loading. Please reload this page.
Enable or disable colored output according to CLICOLOR(_FORCE) - #27867
Enable or disable colored output according to CLICOLOR(_FORCE)#27867jhasse wants to merge 2 commits into
Conversation
rust-highfive
commented
Aug 17, 2015
r? @sfackler (rust_highfive has picked a reviewer for you, use r? to override) |
nagisa
commented
Aug 17, 2015
Is such environment variable in any way standard-ish? I know to try Moreover, this change only touches |
jhasse
commented
Aug 18, 2015
Depends on what you mean. OS X uses them (according to my google research,
The problem of a command line argument is, that it doesn't get propagated
I would love to hear them as this is something I'm dedicated to fix :)
I see. I will look into the test runner then (might take a couple of days). |
nagisa
commented
Aug 18, 2015
You’d usually set
Forcing Windows to use ANSI colours in any way is not acceptable. Windows has its own colouring mechanism; why not specify this for arbitrary colouring mechanism? Since this “spec” is for ANSI colours, we technically already violate it in rustc by using proper colouring mechanisms on each platform. This implementation makes In general, while I’m fine with rustc implementing such things first, I’d feel much better about it if they were more throughout-ly specified. |
jhasse
commented
Aug 18, 2015
As you can see the --color option isn't standarized, so I have to The advantage of CLICOLOR(_FORCE) would be, that programs like a text
This isn't forcing Windows users to use ANSI colors. Windows users who
The spec only tries to standardize what should happen when CLICOLOR
Good point, I've added it in the spec. Thanks :) |
alexcrichton
commented
Aug 19, 2015
I'm also slightly uncomfortable starting to look at some relatively-arbitrary environment variables as well, especially when we have a number of tools to update (as @nagisa mentions, and there's also Cargo). |
Turbo87
commented
Sep 24, 2015
FWIW the most popular tool in the Node.js community is using |
jhasse
commented
Sep 24, 2015
Thanks for the hint! I've created an issue here: chalk/supports-color#32 Another name is also fine, but I really hope that it isn't Rust specific, so that Jenkins (with the ANSI plugin) and other tools (atom-build, ninja, ...) would display color out-of-the-box. |
jhasse
commented
Oct 22, 2015
Rebased and added a new commit which makes sure that only ANSI color sequences are emitted when CLICOLOR(_FORCE) is set and not what is returned by terminfo. This finally enables colored output in atom-build :) |
bors
commented
Nov 23, 2015
☔ The latest upstream changes (presumably #28907) made this pull request unmergeable. Please resolve the merge conflicts. |
bors
commented
Dec 3, 2015
☔ The latest upstream changes (presumably #29999) made this pull request unmergeable. Please resolve the merge conflicts. |
alexcrichton
commented
Jan 27, 2016
I'm going to close this due to inactivity for now. This may want to be discussed externally first (e.g. on the forums) about whether it's a desirable change to push through regardless. |
jhasse
commented
Jan 27, 2016
Please reopen, I've put work into it every time it became unmergeable. Btw: CMake merged my patch a few months ago: https://cmake.org/Bug/view.php?id=15789 |
alexcrichton
commented
Jan 27, 2016
@jhasse I don't think it's clear here that there's consensus to do this, and at this point I don't think that we'll be able to get consensus at this location (this was inactive without comment for ~5 months). It sounds like at this point we'll want to discuss ahead of time, and the forums are currently the best place to do that. |
jhasse
commented
Jan 27, 2016
@alexcrichton Can you open a thread in the forums? I don't know exactly how that thread should look like (also never used the forums). |
alexcrichton
commented
Jan 27, 2016
Ah we currently have a discourse instance over at https://users.rust-lang.org/ and I think you should be able to use your github account to open a thread |
jhasse
commented
Jan 27, 2016
jhasse
commented
Feb 15, 2016
There's been one (positive) response to the forum thread. Can this PR be reopened and can you tell me what is missing for this to be merged? Thanks! :) |
alexcrichton
commented
Feb 22, 2016
cc @rust-lang/tools, do others have opinions here? @jhasse I personally feel that there's so little activity on this (and the thread on the forums) that it's not enough to push forward with this as a general convention, but others may feel differently. |
colin-kiegel
commented
Feb 22, 2016
I would like it. :-) |
brson
commented
Feb 25, 2016
On first glance, I'm disinclined to do this. Can't |
jhasse
commented
Feb 25, 2016
The problem with |
jhasse
commented
May 23, 2016
Any news on this? If you like, we could also discuss this on IRC. |
One other potential issue with this (an issue that also applies to GNU make's Consider if I do like the idea of having a standard way to tell a program "no, really, your output will wind up on the terminal, please print in color even though it doesn't look like a TTY". However, I don't think it makes sense to do so without a solution for this problem. Not showing color output is an annoyance; breaking a build by printing color escape sequences to a pipe would be far worse. (This is also part of why programs like grep are removing environment variables like |
jhasse
commented
May 31, 2016
The issue would be smaller if there was only one enivorment variable ( The Unix tools on OS X already respect
It isn't worse for me. Breaking a build is an annoyance which I can fix with a |
joshtriplett
commented
May 31, 2016
I'd certainly like to see a single variable like CLICOLOR that I can set to enable autodetection (to the extent that programs don't just default to it), and so that people who dislike color output can easily disable it. However, I think forcing color via an environment variable will cause too many problems once more programs start looking at that variable, because the variable will persist in the environment even when redirecting output to somewhere that will not end up on a terminal. And while it's certainly possible that if you set CLICOLOR_FORCE=1 yourself you'd think to set it to 0, the possibility of such breakage would mean programs like make could never set it automatically (the way make currently sets MAKE_TERMOUT). As an alternative solution, programs like make could collect output using a pty rather than a pipe or temp file; that would give the programs it spawns an actual try, so autodetection via isatty would Just Work. |
placrosse
commented
Aug 16, 2016
A decent percentage of prospective Rust users will come from "full featured" IDE environment. Atom is able to provide a fairly nice setup, but the loss of color output is enough to cause people to use a separate terminal window for running cargo, in order to get the colorized text output. This leads to a less integrated experience (which, admittedly, is a minus for some, and a plus for others). If there is a simple, universal means to turn the color on, such that it works in as many arenas Rust apps may be build as possible, it will be an overall win. |
“just pretend to be a TTY” won’t work, as some programs will then (sensibly) assume interactivity and maybe prompt for input. as of now, clang and OSX tools support |
Tools used in an automated build should never prompt interactively; the build scripts should pass them options that answer any questions they might want to ask. |
jhasse
commented
Jan 11, 2017
They use |
joshtriplett
commented
Jan 11, 2017
@jhasse Many people run builds and don't expect those builds to prompt in the middle. Tools usable from automated scripts should always have corresponding command-line options to specify anything they might otherwise want to prompt for, and build scripts should always specify those options. Also, tools that want to prompt should check |
Timmmm
commented
Dec 5, 2019
This should be reopened IMO. There's a clear need for a standard environment variable that determines if colour output should be used. CLICOLOR / CLICOLOR_FORCE is the closest I've ever seen. "Just pretend to be a terminal" is not a very nice solution, and can be very difficult to implement - especially compared to setting a single environment variable. See also Ninja's FAQ. |
joshtriplett
commented
Dec 11, 2019
Force-disabling color from the environment is completely reasonable. Force-enabling it is the problem, and similar features in other programs have caused substantial subtle breakage. |
jhasse
commented
Dec 11, 2019
Can you give an example? You can always just not set this variable (or unset it) if you want to be safe. And that's something that would be a lot easier, if there was only one standardized variable, not multiple ones, to keep in mind. |
joshtriplett
commented
Dec 11, 2019
@jhasse A script might be parsing the output of a command, and thus need it to not have color. Normally, if the script runs such a command and directs its output to a pipe or file, it can expect to automatically not get color. It shouldn't have to also check if code that invoked the script set an environment variable breaking that assumption, and unset that variable. grep has an environment variable |
jhasse
commented
Dec 12, 2019
Thanks! That is definitely a problem, Also keep in mind, that rustc supports JSON output, which is the stable way for tools to parse its output. |
Timmmm
commented
Dec 12, 2019
Yes I think "scripts parsing human-readable command line output" is the real problem in that scenario. |
TL;DR: |
Timmmm
commented
Jun 23, 2026
For posterity, my understanding of what happened is as follows: In 2017 Bixense wrote up how to use This was great, and basically solved the problem, and it gained some traction. Then in 2018 jcs created basically the same thing with The Bixense people eventually updated their page to have logic for supporting all three variables (what a mess). It looks like |
jhasse
commented
Jun 23, 2026
Yes, that's basically what happened :) Just one small correction:
Actually it was in 2015 and both CLICOLOR and CLICOLOR_FORCE were already used by macOS (more precisely FreeBSD where macOS based some user space tools on). |
View all comments
While #14040 already enabled a command line flag to enable or disable colored output, this uses the environment variables
CLICOLORandCLICOLOR_FORCE.CLICOLOR=0would be--color=neverandCLICOLOR_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 :)