fix(windows): enable VT processing on stdout handle for ANSI rendering#2788
Merged
tusharmath merged 4 commits intoantinomyhq:mainfrom Apr 2, 2026
Merged
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fix ANSI escape codes rendering as raw text on certain Windows configurations by enabling
ENABLE_VIRTUAL_TERMINAL_PROCESSINGdirectly on theSTD_OUTPUT_HANDLE.Context
The
enable_ansi_supportcrate sets VT processing on theCONOUT$screen buffer handle, but console mode flags are per-handle on Windows. TheCONOUT$flag does not always propagate to the individualSTD_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
←[33minstead of being interpreted as formatting.Changes
enable_stdout_vt_processing()function that callsSetConsoleModeonSTD_OUTPUT_HANDLEvia thewindows-syscrate to enableENABLE_VIRTUAL_TERMINAL_PROCESSINGmain()Windows init block to call bothenable_ansi_supportand the new functionwindows-sysas a Windows-only dependency with theWin32_System_ConsolefeatureKey Implementation Details
consolecrate (used byindicatif) usesGetConsoleModeto 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 causeconsoleto use ANSI escapes instead, leaving spinner artifacts in the terminal scrollback buffer.enable_ansi_supportcall is preserved as a belt-and-suspenders approach — it coversCONOUT$while the new function coversSTD_OUTPUT_HANDLE.Testing
indicatifstill clean up properly without leaving artifacts in scrollback