summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Peter <mail@david-peter.de>2023-12-11 20:06:10 +0100
committerDavid Peter <david.peter@bosch.com>2023-12-11 20:06:10 +0100
commit4bf875095c82b46093fbdbcd40cdd6dd63a25442 (patch)
tree20bbf71761efda939ed305f248d0bebc76eda63f
parenta78c00b10d27a9fd5d0c77bd9b6aa87bdea65b1e (diff)
Fix NO_COLOR behavior
-rw-r--r--src/main.rs23
1 files changed, 16 insertions, 7 deletions
diff --git a/src/main.rs b/src/main.rs
index 2d1d8d7..cdada0c 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -105,12 +105,13 @@ fn run() -> Result<()> {
.long("color")
.num_args(1)
.value_name("WHEN")
- .value_parser(["always", "auto", "never"])
+ .value_parser(["always", "auto", "never", "force"])
.default_value_if("plain", ArgPredicate::IsPresent, Some("never"))
.default_value("always")
.help(
- "When to use colors. The auto-mode only displays colors if the output \
- goes to an interactive terminal",
+ "When to use colors. The 'auto' mode only displays colors if the output \
+ goes to an interactive terminal. 'force' can be used to override the \
+ NO_COLOR environment variable.",
),
)
.arg(
@@ -338,12 +339,20 @@ fn run() -> Result<()> {
reader.into_inner()
};
+ let no_color = std::env::var_os("NO_COLOR").is_some();
let show_color = match matches.get_one::<String>("color").map(String::as_ref) {
Some("never") => false,
- Some("always") => true,
- _ => supports_color::on(supports_color::Stream::Stdout)
- .map(|level| level.has_basic)
- .unwrap_or(false),
+ Some("always") => !no_color,
+ Some("force") => true,
+ _ => {
+ if no_color {
+ false
+ } else {
+ supports_color::on(supports_color::Stream::Stdout)
+ .map(|level| level.has_basic)
+ .unwrap_or(false)
+ }
+ }
};
let border_style = match matches.get_one::<String>("border").map(String::as_ref) {