Skip to content

Commit

Permalink
feat: enable vt processing on windows (#7158)
Browse files Browse the repository at this point in the history
### 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 <mehul.kar@vercel.com>
  • Loading branch information
chris-olszewski and mehulkar committed Jan 31, 2024
1 parent 14f5207 commit cb9be59
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions crates/turborepo-lib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
21 changes: 20 additions & 1 deletion crates/turborepo-lib/src/shim.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down

0 comments on commit cb9be59

Please sign in to comment.