Skip to content

Commit f7e1e45

Browse files
committed
fix(windows): keep VT enabled during progress
Windows hook installers can toggle off VT processing, which makes indicatif's progress output render as raw ANSI escape sequences. Keep VT enabled while progress bars are active on Windows, and re-enable it after subprocess status/output calls, so install output stays readable even if a child process flips console mode.
1 parent b7ee2df commit f7e1e45

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

crates/prek/src/process.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,13 @@ use tracing::trace;
3737

3838
use crate::git::GIT;
3939

40+
#[cfg(windows)]
41+
fn reenable_vt() {
42+
if *crate::run::USE_COLOR {
43+
let _ = anstyle_query::windows::enable_ansi_colors();
44+
}
45+
}
46+
4047
/// An error from executing a Command
4148
#[derive(Debug, Error)]
4249
pub enum Error {
@@ -176,6 +183,12 @@ impl Cmd {
176183
summary: self.summary.clone(),
177184
cause,
178185
})?;
186+
187+
// Re-enable Windows VT mode in case subprocess corrupted console mode.
188+
// Some tools disable ENABLE_VIRTUAL_TERMINAL_PROCESSING on exit.
189+
#[cfg(windows)]
190+
reenable_vt();
191+
179192
self.maybe_check_output(&output)?;
180193
Ok(output)
181194
}
@@ -283,6 +296,8 @@ impl Cmd {
283296
summary: self.summary.clone(),
284297
cause,
285298
})?;
299+
#[cfg(windows)]
300+
reenable_vt();
286301
self.maybe_check_status(status)?;
287302
Ok(status)
288303
}

0 commit comments

Comments
 (0)