-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Allow to configure colors using an environment variable #3873
Conversation
This commit add support for configuring colors used by cargo through a environment variable (CARGO_COLORS). The used syntax for the environment variable is similar to that one used by gcc (GCC_COLORS). Example: CARGO_COLORS="status=01;2:warn=01;3:error=01;1:default:01;231:blocked=01;4"
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @brson (or someone else) soon. If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes. Please see the contribution instructions for more information. |
☔ The latest upstream changes (presumably #3878) made this pull request unmergeable. Please resolve the merge conflicts. |
Hm this seems like it'd be very unix/linux specific rather than being general to all platforms? This also seems like something that I think that |
This should work on all platforms that uses ANSI escape codes. Which should basic mean everything except cmd.exe. (As noted I only tested it using zsh on linux, so not entirely sure about this.) |
Ah ok, thanks for the clarification and investigation! Seems like a reasonable idea to configure this for multiple kinds of terminals. I'm somewhat wary though of adopting this specific syntax because it seems quite alien on the surface (I can't parse the string above). At the very least we'll need to document this environment variable as well as the syntax associated with it before landing. I wonder if there are perhaps other options for configuring this? Oh I'll also note that all |
I'm rather uncreative with such stuff. So if anyone knows a better syntax for this I'm happy to change it. Using color names instead of the underlying ANSI escape codes does not really work, because the color name would be hard coded to an specific escape code, but the color of those escape codes is configurable by the terminal. (For example one could configure the color named yellow in this schema to a green color.) So this would be rather misleading.
Great. Should I open a issue about this? |
Hm ok, that makes sense. Is there documentation for what all these codes are? As for the syntax and whatnot, I think I'd be in favor of supporting something like this in cargo configuration: [term]
status = 'green'
error = 'red'
# ... which could then be configured with
Does that make sense? |
I've used the wikipedia entry (See the table about sgr parameters) and a shell script to check those codes. #!/bin/bash
echo
echo -e "$(tput bold) reg bld und tput-command-colors$(tput sgr0)"
for i in $(seq 1 255); do
echo " $(tput setaf $i)Text$(tput sgr0) $(tput bold)$(tput setaf $i)Text$(tput sgr0) $(tput sgr 0 1)$(tput setaf $i)Text$(tput sgr0) \$(tput setaf $i)"
done
echo ' Bold $(tput bold)'
echo ' Underline $(tput sgr 0 1)'
echo ' Reset $(tput sgr0)'
echo
[term]
status = 'green'
error = 'red'
# ...
CARGO_TERM_STATUS=green
CARGO_TERM_ERROR=red
# ...
As already noted: This only worked fine as long as the terminal does render those escape codes in the default way. But terminals (or better users) could change this. As far as I understand there seems no way to tell the terminal/shell: "This should be green". One could only tell: "This should be styled using the style number x". Even with this we could theoretically introduce names for those styles as proposed by you (Meaning green maps to style 2 or so). In practice I think it would be rather surprising for user if the he configures the status messages to be green and the resulting output only contains blue status messages. |
I'm a few weeks abroad, so I'm not able to work in this time on this. I will continue the development as soon as I returned. (Feel free to close the pull request in the mean time.) |
Ok, no worries! One thing I also remembered last night is that we probably don't want to only do this in Cargo if we do it. Lots of Rust tools do color: rustc, cargo, rustup, etc. We'd want to be sure to update all of them, not just one. |
I'm going to close this due to inactivity for now, but feel free to resubmit with a rebase! |
The feature branch is now rebased. Should I submit a new pull request or do you want to reopen this one to save the comment history?
Right, but we must start at one place. Maybe we could reuse the code somewhere else? |
Sure yeah, want to open a new PR? |
This commit add support for configuring colors used by cargo through a
environment variable (CARGO_COLORS). The used syntax for the environment
variable is similar to that one used by gcc (GCC_COLORS).
Example: CARGO_COLORS="status=01;2:warn=01;3:error=01;1:default:01;231:blocked=01;4"
The current state should be seen as a proof of concept and demo to see if this functionality is wanted. I've only tested the code on linux so far.
For a final implementation the interpretation of the escape codes may be improved.