Skip to content

Commit

Permalink
fix: display color when NO_COLOR is an empty string
Browse files Browse the repository at this point in the history
  • Loading branch information
acuteenvy committed Nov 4, 2023
1 parent 8bbbd76 commit 4c74925
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
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
6 changes: 3 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -218,12 +218,12 @@ 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 no_color = env::var_os("NO_COLOR").is_some_and(|x| !x.is_empty());

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
}
ColorWhen::Auto => ansi_colors_support && !no_color && interactive_terminal,
};

let ls_colors = if colored_output {
Expand Down

0 comments on commit 4c74925

Please sign in to comment.