From c892e27bc21cdd32449195b643bea398eb339568 Mon Sep 17 00:00:00 2001 From: Jeff Dickey <216188+jdx@users.noreply.github.com> Date: Sun, 13 Oct 2024 21:17:51 -0500 Subject: [PATCH] feat: enable colors for CI services that support it --- src/config/settings.rs | 3 +++ src/env.rs | 18 ++++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/src/config/settings.rs b/src/config/settings.rs index 493d48f98..017c5d35b 100644 --- a/src/config/settings.rs +++ b/src/config/settings.rs @@ -138,6 +138,9 @@ impl Settings { if !settings.color { console::set_colors_enabled(false); console::set_colors_enabled_stderr(false); + } else if *env::COLOR_NONTTY_OK { + console::set_colors_enabled(true); + console::set_colors_enabled_stderr(true); } if settings.ci { settings.yes = true; diff --git a/src/env.rs b/src/env.rs index f4aeb0db2..0cdbb9e22 100644 --- a/src/env.rs +++ b/src/env.rs @@ -164,6 +164,24 @@ pub static GITHUB_TOKEN: Lazy> = Lazy::new(|| { .ok() }); +pub static CLICOLOR: Lazy> = Lazy::new(|| { + if var("CLICOLOR_FORCE").is_ok_and(|v| v != "0") { + Some(true) + } else if let Ok(v) = var("CLICOLOR") { + Some(v != "0") + } else { + None + } +}); +pub static GITHUB_ACTIONS: Lazy = Lazy::new(|| var("GITHUB_ACTIONS").is_ok()); +pub static TRAVIS: Lazy = Lazy::new(|| var("TRAVIS").is_ok()); +pub static CIRCLECI: Lazy = Lazy::new(|| var("CIRCLECI").is_ok()); +pub static APPVEYOR: Lazy = Lazy::new(|| var("APPVEYOR").is_ok()); +pub static GITLAB_CI: Lazy = Lazy::new(|| var("GITLAB_CI").is_ok()); +pub static COLOR_NONTTY_OK: Lazy = Lazy::new(|| { + *CLICOLOR != Some(false) && (*GITHUB_ACTIONS || *TRAVIS || *CIRCLECI || *APPVEYOR || *GITLAB_CI) +}); + // python pub static PYENV_ROOT: Lazy = Lazy::new(|| var_path("PYENV_ROOT").unwrap_or_else(|| HOME.join(".pyenv")));