-
Notifications
You must be signed in to change notification settings - Fork 12.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Enable or disable colored output according to CLICOLOR(_FORCE) #27867
Conversation
r? @sfackler (rust_highfive has picked a reviewer for you, use r? to override) |
Is such environment variable in any way standard-ish? I know to try Moreover, this change only touches |
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). |
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. |
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 :) |
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). |
FWIW the most popular tool in the Node.js community is using |
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. |
a98cb6a
to
5fa7f52
Compare
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 :) |
☔ The latest upstream changes (presumably #28907) made this pull request unmergeable. Please resolve the merge conflicts. |
5fa7f52
to
093102b
Compare
☔ The latest upstream changes (presumably #29999) made this pull request unmergeable. Please resolve the merge conflicts. |
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. |
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 |
@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. |
@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). |
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 |
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! :) |
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. |
I would like it. :-) |
On first glance, I'm disinclined to do this. Can't |
The problem with |
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 |
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 |
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. |
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. |
They use |
@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 |
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. |
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. |
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. |
@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 |
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. |
Yes I think "scripts parsing human-readable command line output" is the real problem in that scenario. |
While #14040 already enabled a command line flag to enable or disable colored output, this uses the environment variables
CLICOLOR
andCLICOLOR_FORCE
.CLICOLOR=0
would be--color=never
andCLICOLOR_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 :)