Skip to content

Commit c9939ca

Browse files
committed
fix(windows): re-enable VT mode after subprocesses
Some Windows hook installers (uv, pip, npm, cargo) disable ENABLE_VIRTUAL_TERMINAL_PROCESSING on exit, which causes indicatif's progress output to render as raw ANSI escape sequences. Re-enable VT mode after subprocess output() and status() calls to restore console state before prek resumes its own output.
1 parent a69f9eb commit c9939ca

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)