Skip to content

Commit 561e31f

Browse files
committed
fix: display color when NO_COLOR is an empty string
1 parent 04e7d2a commit 561e31f

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

Diff for: src/bin/bat/app.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,10 @@ impl App {
207207
|| match self.matches.get_one::<String>("color").map(|s| s.as_str()) {
208208
Some("always") => true,
209209
Some("never") => false,
210-
Some("auto") => env::var_os("NO_COLOR").is_none() && self.interactive_output,
210+
Some("auto") => {
211+
!env::var_os("NO_COLOR").is_some_and(|x| !x.is_empty())
212+
&& self.interactive_output
213+
}
211214
_ => unreachable!("other values for --color are not allowed"),
212215
},
213216
paging_mode,

Diff for: src/bin/bat/clap_app.rs

+6-5
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,12 @@ static VERSION: Lazy<String> = Lazy::new(|| {
1919
});
2020

2121
pub fn build_app(interactive_output: bool) -> Command {
22-
let color_when = if interactive_output && env::var_os("NO_COLOR").is_none() {
23-
ColorChoice::Auto
24-
} else {
25-
ColorChoice::Never
26-
};
22+
let color_when =
23+
if interactive_output && !env::var_os("NO_COLOR").is_some_and(|x| !x.is_empty()) {
24+
ColorChoice::Auto
25+
} else {
26+
ColorChoice::Never
27+
};
2728

2829
let mut app = Command::new(crate_name!())
2930
.version(VERSION.as_str())

0 commit comments

Comments
 (0)