Skip to content
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

Add support for NO_COLOR environment variable #143

Merged
merged 1 commit into from
Jul 25, 2021

Conversation

djmattyg007
Copy link
Contributor

This implements the NO_COLOR environment variable standard, as per
https://no-color.org/

@djmattyg007 djmattyg007 force-pushed the supprt_nocolor_env branch from 3360bc9 to cde3bfb Compare July 8, 2021 22:54
@djmattyg007
Copy link
Contributor Author

I've updated the PR to resolve the issue building on windows.

src/cli/main.rs Outdated
Comment on lines 84 to 87
match mode {
Some(ansi::Mode::Ansi8Bit) => {
if global_matches.subcommand_name() != Some("paint")
&& global_matches.subcommand_name() != Some("colorcheck")
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like that you moved the long print command to a new function. But why split the if into a match+if?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm very new to rust, so I'm not really sure of how best to go about improving this. It's just my inexperience.

I believe you can match against multiple values, but I'm not sure how to include a negation in a match block, which I think you would need to replicate the above check. Would you be able to let me know what I'm missing?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, you had to change it because mode is now an Option<…>. But I think you could still simply compare to Some(ansi::Mode::Ansi8Bit):

                            if mode == Some(ansi::Mode::Ansi8Bit)
                                && global_matches.subcommand_name() != Some("paint")
                                && global_matches.subcommand_name() != Some("colorcheck")

There's not necessarily a need for a match if it's a simple comparison. It would be different if you want to match on Some(_) or Some(mode) and then decide based on the mode.

@sharkdp
Copy link
Owner

sharkdp commented Jul 9, 2021

This looks good, thank you for your contribution!

@djmattyg007 djmattyg007 force-pushed the supprt_nocolor_env branch 2 times, most recently from 78801c0 to d8d0459 Compare July 9, 2021 12:55
@sharkdp sharkdp mentioned this pull request Jul 11, 2021
@djmattyg007
Copy link
Contributor Author

@sharkdp Thank you for your guidance 🙏 I've updated the PR, hopefully it's good to go 🙂

src/ansi.rs Outdated
use std::env;
let env_nocolor = env::var_os("NO_COLOR");
match env_nocolor {
Some(val) => None,
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be Some(_) => None to silence the clippy warnings.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've updated the PR with this change

This implements the NO_COLOR environment variable standard, as per
https://no-color.org/
Copy link
Owner

@sharkdp sharkdp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the updates.

@sharkdp sharkdp merged commit 008a917 into sharkdp:master Jul 25, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants