Skip to content

Commit

Permalink
fix: respect CLICOLOR_FORCE (#3607)
Browse files Browse the repository at this point in the history
Fixes #1836
  • Loading branch information
jdx authored Dec 16, 2024
1 parent ca33515 commit 4923b80
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
8 changes: 7 additions & 1 deletion src/config/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,13 @@ impl Settings {
if !settings.color {
console::set_colors_enabled(false);
console::set_colors_enabled_stderr(false);
} else if ci_info::is_ci() && !cfg!(test) && *env::CLICOLOR != Some(false) {
} else if *env::CLICOLOR_FORCE == Some(true) {
console::set_colors_enabled(true);
console::set_colors_enabled_stderr(true);
} else if *env::CLICOLOR == Some(false) {
console::set_colors_enabled(false);
console::set_colors_enabled_stderr(false);
} else if ci_info::is_ci() && !cfg!(test) {
console::set_colors_enabled_stderr(true);
}
if settings.ci {
Expand Down
5 changes: 4 additions & 1 deletion src/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,8 +200,11 @@ pub static GITHUB_TOKEN: Lazy<Option<String>> = Lazy::new(|| {
pub static TEST_TRANCHE: Lazy<usize> = Lazy::new(|| var_u8("TEST_TRANCHE") as usize);
pub static TEST_TRANCHE_COUNT: Lazy<usize> = Lazy::new(|| var_u8("TEST_TRANCHE_COUNT") as usize);

pub static CLICOLOR_FORCE: Lazy<Option<bool>> =
Lazy::new(|| var("CLICOLOR_FORCE").ok().map(|v| v != "0"));

pub static CLICOLOR: Lazy<Option<bool>> = Lazy::new(|| {
if var("CLICOLOR_FORCE").is_ok_and(|v| v != "0") {
if *CLICOLOR_FORCE == Some(true) {
Some(true)
} else if let Ok(v) = var("CLICOLOR") {
Some(v != "0")
Expand Down
3 changes: 3 additions & 0 deletions src/ui/table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ impl MiseTable {
table
.load_preset(comfy_table::presets::NOTHING)
.set_content_arrangement(ContentArrangement::Dynamic);
if console::colors_enabled() {
table.enforce_styling();
}
if !no_header && console::user_attended() {
let headers = headers.iter().map(Self::header).collect_vec();
table.set_header(headers);
Expand Down

0 comments on commit 4923b80

Please sign in to comment.