Open j4james opened 2 months ago
The more I think about this, the more I believe there may be a bigger problem with win32 input mode in general.
Prior to the new passthrough, the terminal would have appeared as if win32 input mode was not enabled. DECRQM
would report the mode as reset, and ENABLE_VIRTUAL_TERMINAL_INPUT
would generate standard VT input sequences. It was just the internal communication between conhost and Windows Terminal that had win32 input mode enabled.
With the new system, DECRQM
now reports the mode as set by default, but doesn't actually behave that way. If you request ENABLE_VIRTUAL_TERMINAL_INPUT
you're still going to receive standard VT input sequences, unless you explicitly enable win32 input mode yourself.
And apps that do enable win32 input mode will typically disable it when they exit. That's probably OK for WSL apps (assuming we fix the bug reported above), but if you're in a win32 shell, that's going to leave the system in a state where it doesn't report all the key combinations, which is not ideal.
But it's even worse if the app tries to restore the mode to what it detected at startup, because in that case it'll exit with win32 input mode enabled, which will make a WSL shell unusable. And while it may be a good thing for win32 console apps that read INPUT_RECORD
events, it's going to break any apps that are using ENABLE_VIRTUAL_TERMINAL_INPUT
, and which are expecting standard VT input sequences.
I believe what's missing was a call to InjectSequence
in the W32IM_Win32InputMode
handler. The large comment next to it even calls out how we shouldn't bubble up the sequence to the parent terminal.
(#17757 may not help DECRQM
)
Windows Terminal version
Commit 9b21b78feea9ff0a0b9ff2c8fa4b4aa5602d3889
Windows build number
10.0.19045.4780
Other Software
No response
Steps to reproduce
printf "\e[?9001h"; sleep 1; printf "\e[?9001l"; read
showkey -a
Expected Behavior
You should see the VT codes for those keys like this:
Actual Behavior
Neither of those keys are picked up. And I think the problem is the heuristic we're using here:
https://github.com/microsoft/terminal/blob/9b21b78feea9ff0a0b9ff2c8fa4b4aa5602d3889/src/terminal/parser/stateMachine.cpp#L2055-L2056
That works fine if win32 input mode is always on, or always off, but when it's toggled the
_encounteredWin32InputModeSequence
flag is never reset, so that branch is always skipped.I don't think this was an issue prior to the new VT passthrough because we never forwarded win32 input mode changes to conpty, so it should have been permanently enabled (assuming it was supported at all).