fix: clear ENABLE_VIRTUAL_TERMINAL_INPUT on Windows to fix PowerShell arrow keys#7646
fix: clear ENABLE_VIRTUAL_TERMINAL_INPUT on Windows to fix PowerShell arrow keys#7646
Conversation
… arrow keys (#7641) On Windows/PowerShell, the ENABLE_VIRTUAL_TERMINAL_INPUT console flag causes arrow keys to be delivered as ANSI escape sequences instead of native virtual key codes. The survey library's Windows ReadRune only handles native VK codes, so the escape sequence fragments leak through as individual runes. This fix clears the VTI flag after SetTermMode() during input reading. RestoreTermMode() restores the original console state (including VTI if it was originally set). Fixes #7641 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
a14a299 to
09a0768
Compare
Azure Dev CLI Install InstructionsInstall scriptsMacOS/Linux
bash: pwsh: WindowsPowerShell install MSI install Standalone Binary
MSI
Documentationlearn.microsoft.com documentationtitle: Azure Developer CLI reference
|
jongio
left a comment
There was a problem hiding this comment.
This is the right approach - fixing at the console flag level instead of compensating downstream with an escape sequence parser.
Verified the Win32 API usage: 0x0200 is correct for ENABLE_VIRTUAL_TERMINAL_INPUT, the bit-clear with &^ is right, and placing the call after SetTermMode() means RestoreTermMode() correctly restores VTI from its saved original mode. The graceful degradation (log warning on failure, fall back to pre-fix behavior) is a good choice.
Two items before this is merge-ready:
-
CI failure: The Azure DevOps "BuildCLI Windows" job failed. GitHub Actions checks (Windows lint, cross-compile) all pass, so this looks like a test/runtime issue rather than a compilation problem. Worth investigating - could be an unrelated flake or could surface a real interaction.
-
Test coverage: Consider adding a test seam around the console mode calls so you can verify the VTI flag gets cleared (and only on Windows). The function is hard to test directly against real console handles, but injecting the get/set calls would make the mode transition testable and help prevent regressions.
Alternative approach to #7642
This is a draft PR illustrating an alternative fix for #7641 — clearing the
ENABLE_VIRTUAL_TERMINAL_INPUTconsole flag on Windows instead of adding an escape sequence parser.Why
The root cause is that PowerShell enables
ENABLE_VIRTUAL_TERMINAL_INPUT(0x0200) on the console input handle. This makes Windows translate arrow key presses into ANSI escape sequences (ESC [ A) instead of delivering native virtual key codes (VK_UP). The survey library's WindowsReadRune()only handles native VK codes, so the escape fragments leak through as individual runes.How
After
survey.SetTermMode()(which saves the original console state), we additionally clear the VTI flag. The existingRestoreTermMode()restores the original state, re-enabling VTI if it was originally set.Changes
pkg/ux/internal/console_windows.goENABLE_VIRTUAL_TERMINAL_INPUTvia Win32 APIpkg/ux/internal/console_other.gopkg/ux/internal/input.goSetTermMode()Comparison with #7642
[A–[Dfilter false positive on Linux/macOSSee the detailed analysis comment on #7642.
Fixes #7641