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 04e7d2a commit 561e31f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
5 changes: 4 additions & 1 deletion src/bin/bat/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,10 @@ impl App {
|| match self.matches.get_one::<String>("color").map(|s| s.as_str()) {
Some("always") => true,
Some("never") => false,
Some("auto") => env::var_os("NO_COLOR").is_none() && self.interactive_output,
Some("auto") => {
!env::var_os("NO_COLOR").is_some_and(|x| !x.is_empty())
&& self.interactive_output
}
_ => unreachable!("other values for --color are not allowed"),
},
paging_mode,
Expand Down
11 changes: 6 additions & 5 deletions src/bin/bat/clap_app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,12 @@ static VERSION: Lazy<String> = Lazy::new(|| {
});

pub fn build_app(interactive_output: bool) -> Command {
let color_when = if interactive_output && env::var_os("NO_COLOR").is_none() {
ColorChoice::Auto
} else {
ColorChoice::Never
};
let color_when =
if interactive_output && !env::var_os("NO_COLOR").is_some_and(|x| !x.is_empty()) {
ColorChoice::Auto
} else {
ColorChoice::Never
};

let mut app = Command::new(crate_name!())
.version(VERSION.as_str())
Expand Down

0 comments on commit 561e31f

Please sign in to comment.