diff --git a/Cargo.lock b/Cargo.lock index d8330834ab29f..38f498ff72c8a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -11694,6 +11694,7 @@ dependencies = [ "console", "const_format", "convert_case 0.6.0", + "crossterm 0.26.1", "ctrlc", "dialoguer", "directories 4.0.1", diff --git a/crates/turborepo-lib/Cargo.toml b/crates/turborepo-lib/Cargo.toml index 935b54d49538a..bf0bf0907c8fc 100644 --- a/crates/turborepo-lib/Cargo.toml +++ b/crates/turborepo-lib/Cargo.toml @@ -43,6 +43,7 @@ clap = { workspace = true, features = ["derive", "env"] } clap_complete = { workspace = true } command-group = { version = "2.1.0", features = ["with-tokio"] } console = { workspace = true } +crossterm = "0.26" ctrlc = { version = "3.4.0", features = ["termination"] } dialoguer = { workspace = true, features = ["fuzzy-select"] } directories = "4.0.1" diff --git a/crates/turborepo-lib/src/shim.rs b/crates/turborepo-lib/src/shim.rs index db1ac943765de..bc645ad18498c 100644 --- a/crates/turborepo-lib/src/shim.rs +++ b/crates/turborepo-lib/src/shim.rs @@ -290,11 +290,30 @@ impl ShimArgs { if self.no_color { UI::new(true) } else if self.color { + // Do our best to enable ansi colors, but even if the terminal doesn't support + // still emit ansi escape sequences. + Self::supports_ansi(); UI::new(false) - } else { + } else if Self::supports_ansi() { + // If the terminal supports ansi colors, then we can infer if we should emit + // colors UI::infer() + } else { + UI::new(true) } } + + #[cfg(windows)] + fn supports_ansi() -> bool { + // This call has the side effect of setting ENABLE_VIRTUAL_TERMINAL_PROCESSING + // to true. https://learn.microsoft.com/en-us/windows/console/setconsolemode + crossterm::ansi_support::supports_ansi() + } + + #[cfg(not(windows))] + fn supports_ansi() -> bool { + true + } } #[derive(Debug, Clone, Deserialize)]