Skip to content

cmdio: turn on VT processing for Windows consoles at startup - #8240

Merged
pietern merged 3 commits into
mainfrom
pietern/cmdio-conhost-vt
Dec 1, 2026
Merged

pietern merged 3 commits into
mainfrom
pietern/cmdio-conhost-vt

Conversation

@pietern

@pietern pietern commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

Changes

cmdio.NewIO turns on ENABLE_VIRTUAL_TERMINAL_PROCESSING for stdout and stderr when they are Windows consoles and the bit is off (libs/cmdio/vt_windows.go; a no-op elsewhere). It never restores the mode.

This is temporary. Bubble Tea sets the mode when a program starts and restores it when the program exits, so output drawn by a program doesn't need it. It can be removed once all styled output goes through Bubble Tea, which may take a while.

Why

We found this while comparing the Charm v2 swap (#7742) against v1 in real terminals. In PowerShell in a classic console window (conhost), selftest tui colors --lipgloss rendered its swatches on v1 and printed ←[48;2;…m on v2. The same applies to any lipgloss output written outside a Bubble Tea program, such as databricks air get.

How each layer turns VT processing on. All of them call GetConsoleMode, then SetConsoleMode with the bit added:

handle when restores
lipgloss v1 (termenv EnableWindowsANSIConsole) stdout only first styled Render, once per process no
lipgloss v2 (EnableLegacyWindowsANSI) the file the caller passes only when called; lipgloss never calls it no
Bubble Tea v1 and v2 the program's output program start yes, on exit
this PR stdout and stderr cmdio.NewIO no

So v2 drops the only VT enable we had outside Bubble Tea. v1 had gaps of its own, which this also fixes on main:

  • cmdio's color helpers (cmdio.Red and the rest) write raw SGR codes without lipgloss, so they printed as ←[31m on conhost unless a lipgloss render had happened earlier in the process.
  • With stdout redirected, termenv's stdout-only call fails, so styled stderr stayed raw.
  • Bubble Tea restores the mode it found when a program exits. On conhost that's VT off, and lipgloss v1 doesn't turn it on again, so styled output after a prompt in the same process printed raw. This one is from reading the code; the selftest commands on main can't show it.

Measured console modes for a child process: conhost 0x0003 (VT off); Windows Terminal and Git Bash with ConPTY 0x0007 (VT on). So the change does nothing outside conhost.

Landing this before the Charm v2 stack keeps its comparison free of this difference.

Tests

  • go test ./libs/cmdio/...; vet for windows, darwin and linux; golangci-lint (0 issues) for darwin and windows.
  • Live terminals on a Windows 11 VM (conhost, Windows Terminal and Git Bash with ConPTY), screenshotted with and without the change.

This pull request and its description were written by Isaac.

A classic Windows console window (conhost) starts programs with
ENABLE_VIRTUAL_TERMINAL_PROCESSING off, so escape sequences print as
text. lipgloss v1 turned the bit on the first time it rendered a style;
lipgloss v2 leaves it to the caller. Turn it on for stdout and stderr
in cmdio.NewIO, only where it is missing, so styled output renders the
same with either version. Windows Terminal and other ConPTY hosts
already start programs with it on.

This is temporary: Bubble Tea sets the mode for the duration of a
program, so it can go once all styled output is drawn by Bubble Tea.

Co-authored-by: Isaac <no-reply@databricks.com>
@pietern
pietern requested review from a team as code owners December 1, 2026 10:05
Co-authored-by: Isaac <no-reply@databricks.com>
@pietern
pietern requested a review from simonfaltum December 1, 2026 10:11
Co-authored-by: Isaac <no-reply@databricks.com>
@pietern

pietern commented Dec 1, 2026

Copy link
Copy Markdown
Contributor Author
image

@pietern
pietern enabled auto-merge December 1, 2026 10:29
@eng-dev-ecosystem-bot

Copy link
Copy Markdown
Collaborator

✅ Integration test report

Commit: cd68bb2

Run: 46624467179

Env 💚​RECOVERED ✅​pass 🙈​skip Time
💚​ aws linux-2core-8gb 1 88 6 1:42
💚​ aws-windows-latest-4core-16gb 1 88 6 2:42
💚​ azure linux-2core-8gb 1 88 6 1:44
💚​ azure-windows-latest-4core-16gb 1 88 6 3:21
💚​ gcp linux-2core-8gb 1 88 6 1:51
💚​ gcp-windows-latest-4core-16gb 1 88 6 3:10
Test Name aws linux-2core-8gb aws-windows-latest-4core-16gb azure linux-2core-8gb azure-windows-latest-4core-16gb gcp linux-2core-8gb gcp-windows-latest-4core-16gb
💚​ TestAccept 💚​R 💚​R 💚​R 💚​R 💚​R 💚​R
Top 3 slowest tests (at least 2 minutes):
duration env testname
3:20 azure-windows-latest-4core-16gb TestAccept
3:08 gcp-windows-latest-4core-16gb TestAccept
2:41 aws-windows-latest-4core-16gb TestAccept

@simonfaltum simonfaltum left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I found no code correctness blocker in this change. The targeted cmdio tests and Windows/macOS vet checks pass, and CI is green.

[nit] The repo's changelog rules require a fragment for a user-visible fix. The description lists raw-ANSI fixes that also affect main, but cd68bb2ab explicitly removes the fragment. Could you restore a short .nextchanges/cli/ entry, or note the intended release-note exception for this prerequisite?

Non-blocking design question: is NewIO the intended owner of this process-wide console setup, rather than root.initializeIO? The current production callers look safe; this is about making the lifetime of the temporary side effect clear.

@pietern
pietern added this pull request to the merge queue Dec 1, 2026
Merged via the queue into main with commit 9803249 Dec 1, 2026
27 checks passed
@pietern
pietern deleted the pietern/cmdio-conhost-vt branch December 1, 2026 14:59
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.

3 participants