Skip to content

Commit

Permalink
feat: enable colors for CI services that support it
Browse files Browse the repository at this point in the history
  • Loading branch information
jdx committed Oct 14, 2024
1 parent 8ec6fb8 commit c892e27
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/config/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
18 changes: 18 additions & 0 deletions src/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,24 @@ pub static GITHUB_TOKEN: Lazy<Option<String>> = Lazy::new(|| {
.ok()
});

pub static CLICOLOR: Lazy<Option<bool>> = 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<bool> = Lazy::new(|| var("GITHUB_ACTIONS").is_ok());
pub static TRAVIS: Lazy<bool> = Lazy::new(|| var("TRAVIS").is_ok());
pub static CIRCLECI: Lazy<bool> = Lazy::new(|| var("CIRCLECI").is_ok());
pub static APPVEYOR: Lazy<bool> = Lazy::new(|| var("APPVEYOR").is_ok());
pub static GITLAB_CI: Lazy<bool> = Lazy::new(|| var("GITLAB_CI").is_ok());
pub static COLOR_NONTTY_OK: Lazy<bool> = Lazy::new(|| {
*CLICOLOR != Some(false) && (*GITHUB_ACTIONS || *TRAVIS || *CIRCLECI || *APPVEYOR || *GITLAB_CI)
});

// python
pub static PYENV_ROOT: Lazy<PathBuf> =
Lazy::new(|| var_path("PYENV_ROOT").unwrap_or_else(|| HOME.join(".pyenv")));
Expand Down

0 comments on commit c892e27

Please sign in to comment.