-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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) #67177
Conversation
r? @shepmaster (rust_highfive has picked a reviewer for you, use r? to override) |
The job Click to expand the log.
I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
4df7d7e
to
7769634
Compare
The job Click to expand the log.
I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
27a06cd
to
bfaf6ce
Compare
I don't know much about this area of the code.... so I'll pick someone at random r? @BurntSushi |
Nothing in this pull request seems to negate the extensive discussion already on #27867 that made it clear there was no consensus to make such a change. I don't think this should be merged. As before, I think it would be perfectly reasonable to respect People will (incorrectly) set this in their shell or project configuration because they want color when piping to their pager, or other similar reasons. And then much later they'll run into strange issues caused by programs generating color codes where not expected. (As a side note, one potential solution that would work in place of |
☔ The latest upstream changes (presumably #67342) made this pull request unmergeable. Please resolve the merge conflicts. |
@@ -458,7 +458,11 @@ impl ColorConfig { | |||
} | |||
} | |||
ColorConfig::Never => ColorChoice::Never, | |||
ColorConfig::Auto if atty::is(atty::Stream::Stderr) => { | |||
ColorConfig::Auto | |||
if env::var("CLICOLOR_FORCE").unwrap_or("0".to_string()) != "0" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This unnecessarily allocates a string. Something like env::var(...).as_ref().map(|s| &**s).unwrap_or("0")
should work. Also I think it would be nicer to use ColorConfig::Auto => { if { ... } else { ... } }
instead.
let term = match env::var("TERM") { | ||
Ok(name) => TermInfo::from_name(&name), | ||
Err(..) => return Err(Error::TermUnset), | ||
}; | ||
|
||
if term.is_err() && env::var("MSYSCON").ok().map_or(false, |s| "mintty.exe" == s) { | ||
if term.is_err() && (env::var("MSYSCON").map_or(false, |s| "mintty.exe" == s) || | ||
env::var("CLICOLOR").unwrap_or("0".to_string()) != "0") { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is confusing what the condition is. It is easy to overlook the start and end of (...)
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👎 See extensive discussion on #27867.
Doesn't seem to be much interest in having this. Closing it. Thanks for taking the time to contribute :) |
That's because the points you made are not something which can be negated with code. I've answered to your comment and IMHO addressed your concerns. Please answer there instead of rephrasing them here while ignoring my counter arguments. I must say that the way this went down feels VERY frustrating to me. The first PR was closed with the following comment:
I've done exactly that: #27867 (comment)
Well, most people just workaround the issue. Or do not care that much about colors to look at open PRs all the time. Maybe some kind of poll could shed light on this? |
I would recommend writing an RFC to add this; it can likely be relatively short, but it would be a good way to build consensus (doing so in PR comments for contentious changes doesn't work too well, in practice, as they do not have good visibility). |
Thanks, I will have a look :) |
This problem cannot be solved solely with code, no. It could, however, be solved with a change to the specification, and corresponding code implementing the new specification. One possible proposal: an environment variable that specifies the device/inode pair of the file to force sending color to. A program looking to emit color to stdout would call
I would have continued to answer there, but that issue was closed, and this one was still open without any record of those concerns. (I also don't believe a new issue should have been opened at all. If the problems had been addressed, that issue could have been reopened.) And no, I do not believe you have addressed these concerns.
I absolutely understand and appreciate that. I have been in that position before, and it can be frustrating to not have an obvious next step. I'm hoping that the above proposal helps. (If you don't like that proposal, please feel free to make an alternative one that solves the same problem.) I think you received somewhat mixed messages, in this case. I don't believe that the other issue should have been closed due to "inactivity", for instance, as opposed to "lack of consensus for this change". |
Thanks for your answer :) Sorry for mine that was a bit harsh.
That
I thought Windows doesn't use files for ttys? How would it work on Windows? |
@jhasse What I'm proposing would get inherited by subprocesses, but only if their output is directed to a specific place (as indicated in the environment variable). You'd be able to direct output to a pipe or file and get color, and any output going to that pipe or file would use color, but any output that a script redirects to a different pipe or file would not use color. Suppose that
I'm talking about pipes, here. This could work on Windows using |
Okay, that case is already somewhat covered by The currently unsolvable issue comes when scripts do something like this: rustc foo > tmpfile
cat tmpfile Doesn't have to be a file, most of the time it's a buffer, e.g. with |
Updated version of #27867.
Also related: https://users.rust-lang.org/t/enable-or-disable-colored-output-according-to-clicolor--force/4445