Hard reset disables win32-input-mode #19999

Closed
opened 2026-01-31 07:00:05 +00:00 by claunia · 4 comments
Owner

Originally created by @j4james on GitHub (May 27, 2023).

Windows Terminal version

1.18.1421.0

Windows build number

10.0.19045.2913

Other Software

No response

Steps to reproduce

  1. Start Windows Terminal.
  2. Open up a WSL bash shell with the debug tap enabled.
  3. Press some keys and note the escape sequences that are generated in the debug pane.
  4. Execute reset.
  5. Press some more keys and note what is generated in the debug pane now.

Expected Behavior

I'd expected to see win32-input-mode escape sequences for every key press.

Actual Behavior

After the reset, win32-input-mode is disabled, and the key presses are just passed through as ASCII, or basic VT100 escape for things like arrow keys.

I think this was a regression introduced in PR #14444 when I made the RIS operation fully reset all input modes. Technically that was the right thing to do, but for conpty to work correctly, it would now also need to re-request any non-default modes it needs from the conpty client.

I'm not sure how best to fix this. The HardReset implementation can't just return false to pass through the RIS sequence anymore. It would probably need to call a new "reset" method in the renderer that the VT engine would pass on as an RIS with additional mode requests. It must also then return true to prevent the state machine trying to pass through the RIS a second time.

I don't know if anyone has any better ideas.

Originally created by @j4james on GitHub (May 27, 2023). ### Windows Terminal version 1.18.1421.0 ### Windows build number 10.0.19045.2913 ### Other Software _No response_ ### Steps to reproduce 1. Start Windows Terminal. 2. Open up a WSL bash shell with the debug tap enabled. 3. Press some keys and note the escape sequences that are generated in the debug pane. 4. Execute `reset`. 5. Press some more keys and note what is generated in the debug pane now. ### Expected Behavior I'd expected to see win32-input-mode escape sequences for every key press. ### Actual Behavior After the reset, win32-input-mode is disabled, and the key presses are just passed through as ASCII, or basic VT100 escape for things like arrow keys. I think this was a regression introduced in PR #14444 when I made the `RIS` operation fully reset all input modes. Technically that was the right thing to do, but for conpty to work correctly, it would now also need to re-request any non-default modes it needs from the conpty client. I'm not sure how best to fix this. The `HardReset` implementation can't just return false to pass through the `RIS` sequence anymore. It would probably need to call a new "reset" method in the renderer that the VT engine would pass on as an `RIS` with additional mode requests. It must also then return true to prevent the state machine trying to pass through the `RIS` a second time. I don't know if anyone has any better ideas.
claunia added the Issue-BugIn-PRArea-VTNeeds-Tag-FixProduct-Conpty labels 2026-01-31 07:00:05 +00:00
Author
Owner

@j4james commented on GitHub (May 27, 2023):

Having looked at the VtEngine::RequestWin32Input implementation here:

c9e993a38e/src/renderer/vt/state.cpp (L542-L548)

it appears we also need to request the focus event mode. Otherwise that's also something that'll stop working after a hard reset.

@j4james commented on GitHub (May 27, 2023): Having looked at the `VtEngine::RequestWin32Input` implementation here: https://github.com/microsoft/terminal/blob/c9e993a38ec04833e15edac230300948a0fab83b/src/renderer/vt/state.cpp#L542-L548 it appears we also need to request the focus event mode. Otherwise that's also something that'll stop working after a hard reset.
Author
Owner

@j4james commented on GitHub (May 28, 2023):

I realised there's an easier way of handling this which doesn't require any new render APIs. We already have access to the StateMachine instance from within AdaptDispatch, and that gives us the ability pass through sequences directly to the conpty client.

So a simple fix would be to add something like this to the end of the HardReset method.

if (_api.IsConsolePty())
{
    auto& stateMachine = _api.GetStateMachine();
    if (stateMachine.FlushToTerminal())
    {
        auto& engine = stateMachine.Engine();
        engine.ActionPassThroughString(L"\033[?9001;1004h");
    }
}

The FlushToTerminal call should pass through the pending RIS sequence, and then we follow that up with mode requests to enable win32 input and focus events.

The only downside I can see is that we're essentially duplicating the code from VtEngine::RequestWin32Input, which runs the risk of the two getting out of sync, but that could be mitigated with a couple of comments. It's not as clean as I'd like, but it's probably the simplest option.

@j4james commented on GitHub (May 28, 2023): I realised there's an easier way of handling this which doesn't require any new render APIs. We already have access to the `StateMachine` instance from within `AdaptDispatch`, and that gives us the ability pass through sequences directly to the conpty client. So a simple fix would be to add something like this to the end of the `HardReset` method. ```cpp if (_api.IsConsolePty()) { auto& stateMachine = _api.GetStateMachine(); if (stateMachine.FlushToTerminal()) { auto& engine = stateMachine.Engine(); engine.ActionPassThroughString(L"\033[?9001;1004h"); } } ``` The `FlushToTerminal` call should pass through the pending `RIS` sequence, and then we follow that up with mode requests to enable win32 input and focus events. The only downside I can see is that we're essentially duplicating the code from `VtEngine::RequestWin32Input`, which runs the risk of the two getting out of sync, but that could be mitigated with a couple of comments. It's not as clean as I'd like, but it's probably the simplest option.
Author
Owner

@DHowett commented on GitHub (May 28, 2023):

I'm alright with "duplicate with comment", until we get to 3 places that need to do it. Then we can figure it out 🙂

Excellent catch!

@DHowett commented on GitHub (May 28, 2023): I'm alright with "duplicate with comment", until we get to 3 places that need to do it. Then we can figure it out 🙂 Excellent catch!
Author
Owner

@j4james commented on GitHub (May 29, 2023):

FYI, the easy fix I suggested above isn't quite as easy as I had originally thought, because those modes are currently only sent when the conpty client requests them (with the --win32input command line option). And since AdaptDispatch has no knowledge of that option, we'd still need additional APIs to figure that out somehow.

That said, I have no idea why we have that command line option in the first place. Why don't we send those mode requests regardless? If the connected conpty client doesn't recognise the mode, it'll assumedly just ignore it. We even have a comment in the code saying exactly that!

c9e993a38e/src/host/VtIo.cpp (L268-L275)

So my question is, do we we really need that option, and thus a bunch of additional framework to make it accessible to AdaptDispatch, or can we just get rid of it altogether?

@j4james commented on GitHub (May 29, 2023): FYI, the easy fix I suggested above isn't quite as easy as I had originally thought, because those modes are currently only sent when the conpty client requests them (with the `--win32input` command line option). And since `AdaptDispatch` has no knowledge of that option, we'd still need additional APIs to figure that out somehow. That said, I have no idea why we have that command line option in the first place. Why don't we send those mode requests regardless? If the connected conpty client doesn't recognise the mode, it'll assumedly just ignore it. We even have a comment in the code saying exactly that! https://github.com/microsoft/terminal/blob/c9e993a38ec04833e15edac230300948a0fab83b/src/host/VtIo.cpp#L268-L275 So my question is, do we we really need that option, and thus a bunch of additional framework to make it accessible to `AdaptDispatch`, or can we just get rid of it altogether?
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#19999