Skip to content

Commit

Permalink
Merge pull request #1421 from acuteenvy/fix-no-color
Browse files Browse the repository at this point in the history
fix: display color when `NO_COLOR` is an empty string
  • Loading branch information
tavianator committed Nov 7, 2023
2 parents 8bbbd76 + ad5fb44 commit d62bbbb
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
};

Expand Down

0 comments on commit d62bbbb

Please sign in to comment.