Skip to content

Conversation

@shaanmajid
Copy link
Contributor

@shaanmajid shaanmajid commented Jan 22, 2026

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 during prek install.

Re-enables VT mode after subprocess output() and status() calls to restore console state before prek resumes its own output.

Fixes #1237

@codecov
Copy link

codecov bot commented Jan 22, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 91.35%. Comparing base (a69f9eb) to head (dd596f1).

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #1465   +/-   ##
=======================================
  Coverage   91.35%   91.35%           
=======================================
  Files          87       87           
  Lines       18187    18189    +2     
=======================================
+ Hits        16615    16617    +2     
  Misses       1572     1572           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@github-actions
Copy link

github-actions bot commented Jan 22, 2026

📦 Cargo Bloat Comparison

Binary size change: +0.00% (22.5 MiB → 22.5 MiB)

Expand for cargo-bloat output

Head Branch Results

 File  .text    Size           Crate Name
 0.3%   0.8% 71.7KiB           prek? <prek::cli::Command as clap_builder::derive::Subcommand>::augment_subcommands
 0.3%   0.6% 59.2KiB            prek prek::languages::<impl prek::config::Language>::run::{{closure}}::{{closure}}
 0.2%   0.6% 55.6KiB            prek prek::languages::<impl prek::config::Language>::run::{{closure}}::{{closure}}
 0.2%   0.5% 43.4KiB            prek prek::identify::by_extension::{{closure}}
 0.2%   0.5% 43.3KiB            prek prek::run::{{closure}}
 0.2%   0.5% 42.4KiB            prek prek::languages::<impl prek::config::Language>::install::{{closure}}
 0.2%   0.4% 41.7KiB            prek prek::cli::run::run::run::{{closure}}
 0.1%   0.3% 31.8KiB           prek? <prek::cli::RunArgs as clap_builder::derive::Args>::augment_args
 0.1%   0.2% 21.6KiB            prek prek::hooks::meta_hooks::MetaHooks::run::{{closure}}
 0.1%   0.2% 21.0KiB    clap_builder clap_builder::parser::parser::Parser::get_matches_with
 0.1%   0.2% 20.8KiB            prek prek::archive::unzip::{{closure}}
 0.1%   0.2% 20.0KiB cargo_metadata? <cargo_metadata::_::<impl serde_core::de::Deserialize for cargo_metadata::Package>::deserialize::__Visitor as serde_core::de::Visitor>::visit_map
 0.1%   0.2% 19.8KiB            prek prek::hooks::meta_hooks::MetaHooks::run::{{closure}}
 0.1%   0.2% 19.4KiB            prek prek::cli::run::filter::collect_files_from_args::{{closure}}
 0.1%   0.2% 19.4KiB            prek prek::cli::run::filter::collect_files_from_args::{{closure}}
 0.1%   0.2% 19.3KiB            prek <prek::languages::ruby::ruby::Ruby as prek::languages::LanguageImpl>::install::{{closure}}
 0.1%   0.2% 18.6KiB            ring ring_core_0_17_14__x25519_ge_frombytes_vartime
 0.1%   0.2% 18.5KiB            prek prek::hook::HookBuilder::build::{{closure}}
 0.1%   0.2% 18.5KiB            prek prek::hook::HookBuilder::build::{{closure}}
 0.1%   0.2% 18.5KiB            prek prek::hook::HookBuilder::build::{{closure}}
36.9%  91.6%  8.3MiB                 And 20035 smaller methods. Use -n N to show more.
40.2% 100.0%  9.1MiB                 .text section size, the file size is 22.5MiB

Base Branch Results

 File  .text    Size           Crate Name
 0.3%   0.8% 71.7KiB           prek? <prek::cli::Command as clap_builder::derive::Subcommand>::augment_subcommands
 0.3%   0.6% 59.2KiB            prek prek::languages::<impl prek::config::Language>::run::{{closure}}::{{closure}}
 0.2%   0.6% 55.6KiB            prek prek::languages::<impl prek::config::Language>::run::{{closure}}::{{closure}}
 0.2%   0.5% 43.4KiB            prek prek::identify::by_extension::{{closure}}
 0.2%   0.5% 43.3KiB            prek prek::run::{{closure}}
 0.2%   0.5% 42.4KiB            prek prek::languages::<impl prek::config::Language>::install::{{closure}}
 0.2%   0.4% 41.7KiB            prek prek::cli::run::run::run::{{closure}}
 0.1%   0.3% 31.8KiB           prek? <prek::cli::RunArgs as clap_builder::derive::Args>::augment_args
 0.1%   0.2% 21.6KiB            prek prek::hooks::meta_hooks::MetaHooks::run::{{closure}}
 0.1%   0.2% 21.0KiB    clap_builder clap_builder::parser::parser::Parser::get_matches_with
 0.1%   0.2% 20.8KiB            prek prek::archive::unzip::{{closure}}
 0.1%   0.2% 20.0KiB cargo_metadata? <cargo_metadata::_::<impl serde_core::de::Deserialize for cargo_metadata::Package>::deserialize::__Visitor as serde_core::de::Visitor>::visit_map
 0.1%   0.2% 19.8KiB            prek prek::hooks::meta_hooks::MetaHooks::run::{{closure}}
 0.1%   0.2% 19.4KiB            prek prek::cli::run::filter::collect_files_from_args::{{closure}}
 0.1%   0.2% 19.4KiB            prek prek::cli::run::filter::collect_files_from_args::{{closure}}
 0.1%   0.2% 19.3KiB            prek <prek::languages::ruby::ruby::Ruby as prek::languages::LanguageImpl>::install::{{closure}}
 0.1%   0.2% 18.6KiB            ring ring_core_0_17_14__x25519_ge_frombytes_vartime
 0.1%   0.2% 18.5KiB            prek prek::hook::HookBuilder::build::{{closure}}
 0.1%   0.2% 18.5KiB            prek prek::hook::HookBuilder::build::{{closure}}
 0.1%   0.2% 18.5KiB            prek prek::hook::HookBuilder::build::{{closure}}
36.9%  91.6%  8.3MiB                 And 20035 smaller methods. Use -n N to show more.
40.2% 100.0%  9.1MiB                 .text section size, the file size is 22.5MiB

@shaanmajid shaanmajid force-pushed the fix/windows-ansi-1237 branch 3 times, most recently from f7e1e45 to 762d114 Compare January 22, 2026 20:34
@shaanmajid
Copy link
Contributor Author

Keeping in draft until @chrisoro or someone with a Windows machine can confirm this actually fixes the issue lolol

@chrisoro
Copy link

Any chance to build arm64 version of it? I won't have access to my amd64 win machine until end of next week. I do have windows on arm as a vm on my mac

@shaanmajid
Copy link
Contributor Author

shaanmajid commented Jan 24, 2026

Just did a dummy change to build-binaries.yml to trigger the build job and build ARM Windows binaries. Those artifacts can be found at https://github.com/j178/prek/actions/runs/21322541711#artifacts.

@chrisoro The link for the ARM Windows standalone binary specifically is https://github.com/j178/prek/actions/runs/21322541711/artifacts/5245733919. Looks like it's a zip file in another zip file lol, but the inner zip has a prek.exe which is what you should be able to test with. The rest of the instructions I left in my issue comment should still apply.

Let me know how it goes!

@chrisoro
Copy link

chrisoro commented Jan 28, 2026

Tried the arm executable and it shows the same errors in both cmd and powershell. Maybe it is the region/language setting in Windows? Mine is set to Germany / German

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.
Subprocesses like uv/pip/npm can disable ENABLE_VIRTUAL_TERMINAL_PROCESSING
while indicatif's spinner is actively rendering, causing raw ANSI escape
sequences to appear mid-install.

Add a Windows-only background thread that re-enables VT mode every 200ms
(matching the spinner tick rate) while progress bars are visible. The thread
is scoped to ProgressReporter lifetime and only spawns when color is enabled.
@shaanmajid shaanmajid force-pushed the fix/windows-ansi-1237 branch from bf6d4cc to dd596f1 Compare January 28, 2026 20:13
@shaanmajid
Copy link
Contributor Author

Sad, can you try the latest build? Tried some more changes.

@chrisoro
Copy link

Nice, this seems to have done the trick. I can't overserve the broken output anymore. See: https://streamable.com/qaa5qs

@shaanmajid
Copy link
Contributor Author

Awesome! Just to confirm, you were able to consistently reproduce in both cmd and powershell in prek 0.3.0, but the bug is consistently gone in both shells with the fix?

@shaanmajid shaanmajid marked this pull request as ready for review January 30, 2026 17:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Coloring on Powershell broken

2 participants