fix: display color when NO_COLOR is an empty string

This commit is contained in:
Lena 2023-11-04 14:22:54 +01:00
parent 8bbbd7679b
commit ad5fb44ddc
No known key found for this signature in database
GPG Key ID: AB5FC04C3C94443F
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
}
};