Merge pull request #1421 from acuteenvy/fix-no-color

fix: display color when `NO_COLOR` is an empty string
This commit is contained in:
Tavian Barnes 2023-11-07 13:29:50 -05:00 committed by GitHub
commit d62bbbbcd1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 1 deletions

View File

@ -8,6 +8,8 @@
## Bugfixes
- Fix `NO_COLOR` support, see #1421 (@acuteenvy)
## Changes
- The default number of threads is now constrained to be at most 16. This should improve startup time on

View File

@ -218,11 +218,13 @@ fn construct_config(mut opts: Opts, pattern_regexps: &[String]) -> Result<Config
let ansi_colors_support = true;
let interactive_terminal = std::io::stdout().is_terminal();
let colored_output = match opts.color {
ColorWhen::Always => true,
ColorWhen::Never => false,
ColorWhen::Auto => {
ansi_colors_support && env::var_os("NO_COLOR").is_none() && interactive_terminal
let no_color = env::var_os("NO_COLOR").is_some_and(|x| !x.is_empty());
ansi_colors_support && !no_color && interactive_terminal
}
};