Skip to content

Commit cb9be59

Browse files
feat: enable vt processing on windows (#7158)
### Description If we're on windows and are attempting to emit colors, help our users by setting [`ENABLE_VIRTUAL_TERMINAL_PROCESSING`](https://learn.microsoft.com/en-us/windows/console/setconsolemode) which allows ANSI color escape sequences to be respected by the Windows console. This might already be set to true by some users, but it is not enabled by default by Windows. ### Testing Instructions Look at the pretty colors on Windows! ![cmdp](https://github.com/vercel/turbo/assets/4131117/382fa484-03be-4005-9b95-0d4ab7a7aa26) ![pwsh](https://github.com/vercel/turbo/assets/4131117/08175677-1014-4264-b58f-26c991067ec5) (My default powershell colors are horrible and end up making the `docs:build` prefix invisible) ![gitbash](https://github.com/vercel/turbo/assets/4131117/d119347b-7ecd-40e3-9102-c9e3c2e089cc) Closes TURBO-2186 --------- Co-authored-by: Chris Olszewski <Chris Olszewski> Co-authored-by: Mehul Kar <[email protected]>
1 parent 14f5207 commit cb9be59

File tree

3 files changed

+22
-1
lines changed

3 files changed

+22
-1
lines changed

Cargo.lock

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/turborepo-lib/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ clap = { workspace = true, features = ["derive", "env"] }
4343
clap_complete = { workspace = true }
4444
command-group = { version = "2.1.0", features = ["with-tokio"] }
4545
console = { workspace = true }
46+
crossterm = "0.26"
4647
ctrlc = { version = "3.4.0", features = ["termination"] }
4748
dialoguer = { workspace = true, features = ["fuzzy-select"] }
4849
directories = "4.0.1"

crates/turborepo-lib/src/shim.rs

+20-1
Original file line numberDiff line numberDiff line change
@@ -290,11 +290,30 @@ impl ShimArgs {
290290
if self.no_color {
291291
UI::new(true)
292292
} else if self.color {
293+
// Do our best to enable ansi colors, but even if the terminal doesn't support
294+
// still emit ansi escape sequences.
295+
Self::supports_ansi();
293296
UI::new(false)
294-
} else {
297+
} else if Self::supports_ansi() {
298+
// If the terminal supports ansi colors, then we can infer if we should emit
299+
// colors
295300
UI::infer()
301+
} else {
302+
UI::new(true)
296303
}
297304
}
305+
306+
#[cfg(windows)]
307+
fn supports_ansi() -> bool {
308+
// This call has the side effect of setting ENABLE_VIRTUAL_TERMINAL_PROCESSING
309+
// to true. https://learn.microsoft.com/en-us/windows/console/setconsolemode
310+
crossterm::ansi_support::supports_ansi()
311+
}
312+
313+
#[cfg(not(windows))]
314+
fn supports_ansi() -> bool {
315+
true
316+
}
298317
}
299318

300319
#[derive(Debug, Clone, Deserialize)]

0 commit comments

Comments
 (0)