Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix NO_COLOR behavior #210

Merged
merged 1 commit into from
Dec 11, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 16 additions & 7 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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) {
Expand Down