Skip to content

Commit f510f58

Browse files
authored
fix: enable/disable global yansi color with flag (#12297)
* fix: enable/disable global yansi color with flag * update
1 parent a446ab3 commit f510f58

File tree

2 files changed

+16
-8
lines changed

2 files changed

+16
-8
lines changed

crates/cli/src/opts/global.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,17 +54,24 @@ impl GlobalArgs {
5454
/// Initialize the global options.
5555
pub fn init(&self) -> eyre::Result<()> {
5656
// Set the global shell.
57-
self.shell().set();
57+
let shell = self.shell();
58+
// Argument takes precedence over the env var global color choice.
59+
match shell.color_choice() {
60+
ColorChoice::Auto => {}
61+
ColorChoice::Always => yansi::enable(),
62+
ColorChoice::Never => yansi::disable(),
63+
}
64+
shell.set();
5865

5966
// Initialize the thread pool only if `threads` was requested to avoid unnecessary overhead.
6067
if self.threads.is_some() {
6168
self.force_init_thread_pool()?;
6269
}
6370

6471
// Display a warning message if the current version is not stable.
65-
if std::env::var("FOUNDRY_DISABLE_NIGHTLY_WARNING").is_err()
72+
if IS_NIGHTLY_VERSION
6673
&& !self.json
67-
&& IS_NIGHTLY_VERSION
74+
&& std::env::var_os("FOUNDRY_DISABLE_NIGHTLY_WARNING").is_none()
6875
{
6976
let _ = sh_warn!("{}", NIGHTLY_VERSION_WARNING_MESSAGE);
7077
}

crates/forge/tests/fixtures/colored_traces.svg

Lines changed: 6 additions & 5 deletions
Loading

0 commit comments

Comments
 (0)