Skip to content

fix(windows): enable VT processing on stdout handle for ANSI rendering#2788

Merged
tusharmath merged 4 commits intoantinomyhq:mainfrom
stier1ba:fix/windows-stdout-vt-processing
Apr 2, 2026
Merged

fix(windows): enable VT processing on stdout handle for ANSI rendering#2788
tusharmath merged 4 commits intoantinomyhq:mainfrom
stier1ba:fix/windows-stdout-vt-processing

Conversation

@stier1ba
Copy link
Copy Markdown
Contributor

@stier1ba stier1ba commented Apr 2, 2026

Summary

Fix ANSI escape codes rendering as raw text on certain Windows configurations by enabling ENABLE_VIRTUAL_TERMINAL_PROCESSING directly on the STD_OUTPUT_HANDLE.

Context

The enable_ansi_support crate sets VT processing on the CONOUT$ screen buffer handle, but console mode flags are per-handle on Windows. The CONOUT$ flag does not always propagate to the individual STD_OUTPUT_HANDLE — particularly on older Windows builds, when cmd.exe is launched in certain ways, or when handles have been duplicated.

Without VT processing on stdout, ANSI escape codes from forge's markdown renderer (bold, colors, inline code styling) are displayed as raw text like ←[33m instead of being interpreted as formatting.

Changes

  • Added enable_stdout_vt_processing() function that calls SetConsoleMode on STD_OUTPUT_HANDLE via the windows-sys crate to enable ENABLE_VIRTUAL_TERMINAL_PROCESSING
  • Updated the main() Windows init block to call both enable_ansi_support and the new function
  • Added windows-sys as a Windows-only dependency with the Win32_System_Console feature

Key Implementation Details

  • Stderr is intentionally left unchanged: The console crate (used by indicatif) uses GetConsoleMode to detect VT support and switches between Win32 Console APIs and ANSI escapes accordingly. The Win32 Console API path produces clean scrollback when clearing spinner lines. Enabling VT on stderr would cause console to use ANSI escapes instead, leaving spinner artifacts in the terminal scrollback buffer.
  • The existing enable_ansi_support call is preserved as a belt-and-suspenders approach — it covers CONOUT$ while the new function covers STD_OUTPUT_HANDLE.

Testing

  1. Build and run forge on Windows in cmd.exe
  2. Verify that markdown output (bold, colors, inline code) renders with proper formatting
  3. Verify that spinner/progress indicators from indicatif still clean up properly without leaving artifacts in scrollback

The enable_ansi_support crate sets ENABLE_VIRTUAL_TERMINAL_PROCESSING on the CONOUT$ handle, but console mode flags are per-handle on Windows. The CONOUT$ flag may not propagate to the individual STD_OUTPUT_HANDLE on all configurations (e.g. older builds, cmd.exe launched in certain ways, or when handles have been duplicated).

Without VT processing on stdout, ANSI escape codes from forge's markdown renderer (bold, colors, inline code styling) are displayed as raw text like ←[33m instead of being interpreted as formatting.

This change adds a direct call to SetConsoleMode on STD_OUTPUT_HANDLE via the windows-sys crate, in addition to the existing enable_ansi_support call. Stderr is intentionally left unchanged to avoid breaking indicatif spinner cleanup.

Co-Authored-By: ForgeCode <noreply@forgecode.dev>
@github-actions github-actions bot added the type: fix Iterations on existing features or infrastructure. label Apr 2, 2026
@CLAassistant
Copy link
Copy Markdown

CLAassistant commented Apr 2, 2026

CLA assistant check
All committers have signed the CLA.

@tusharmath tusharmath enabled auto-merge (squash) April 2, 2026 11:10
@tusharmath tusharmath merged commit d9c5f24 into antinomyhq:main Apr 2, 2026
9 checks passed
@stier1ba stier1ba deleted the fix/windows-stdout-vt-processing branch April 3, 2026 03:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type: fix Iterations on existing features or infrastructure.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants