Skip to content

Enable ANSI rendering in Windows conhost - #24

Closed
linux-china with Copilot wants to merge 3 commits into
masterfrom
copilot/fix-enable-virtual-terminal-processing
Closed

Enable ANSI rendering in Windows conhost#24
linux-china with Copilot wants to merge 3 commits into
masterfrom
copilot/fix-enable-virtual-terminal-processing

Conversation

Copilot AI commented Sep 3, 2026

Copy link
Copy Markdown

tk emitted ANSI color sequences on Windows without enabling virtual terminal processing, so default conhost sessions displayed raw escape codes instead of colored output. This change enables the required console mode at process startup so existing ANSI output renders correctly.

  • Windows console initialization

    • Enable ENABLE_VIRTUAL_TERMINAL_PROCESSING for both stdout and stderr when tk starts.
    • Skip mode updates when the handle is not a console or the flag is already set.
  • Dependency surface

    • Add a Windows-only windows-sys dependency for the console API calls.
    • Keep the change isolated to the tk entrypoint; non-Windows behavior remains unchanged.
  • Coverage

    • Add focused unit tests for the mode-bit helper to verify the VT flag is added without clearing existing flags.
#[cfg(windows)]
fn enable_virtual_terminal_processing() {
    for handle in [STD_OUTPUT_HANDLE, STD_ERROR_HANDLE] {
        let std_handle = unsafe { GetStdHandle(handle) };
        let mut mode = 0;
        if unsafe { GetConsoleMode(std_handle, &mut mode) } == 0 {
            continue;
        }
        let new_mode = mode | ENABLE_VIRTUAL_TERMINAL_PROCESSING;
        if new_mode != mode {
            unsafe { SetConsoleMode(std_handle, new_mode) };
        }
    }
}

Copilot AI and others added 2 commits September 3, 2026 07:42
Co-authored-by: linux-china <46711+linux-china@users.noreply.github.com>
Co-authored-by: linux-china <46711+linux-china@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix Windows ENABLE_VIRTUAL_TERMINAL_PROCESSING flag application Enable ANSI rendering in Windows conhost Sep 3, 2026
Copilot AI requested a review from linux-china September 3, 2026 07:46
@linux-china linux-china closed this Sep 3, 2026
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.

Windows: ENABLE_VIRTUAL_TERMINAL_PROCESSING flag not applied when invoked

2 participants