Update 'restart connection' action to reset internal state#19971
Update 'restart connection' action to reset internal state#19971carlos-zamora merged 3 commits intomainfrom
Conversation
DHowett
left a comment
There was a problem hiding this comment.
Hmmmm. I don't love how we have to send this all the way down through the RIS handler. However, it's also the only thing that knows the full gamut of things that need done to reset the terminal.
I'd love @j4james' opinion on the layering here.
If I had nits to pick, they would be:
ResetConnection should be named HardResetWithoutErase, clearBuffers should be named erase, BufferClear should be called Erase; later we can also add TermControl::HardReset which allows whoever's driving terminal to reset it with all the usual ceremony.
Also, why does TerminalCore need to reach into StateMachine? What state is stuck in stateMachine?
|
Yeah, I'm a little uncomfortable with this partial hard reset concept. If we were using either a plain hard reset, or a plain soft reset that would be fine. It may not be exactly what we want, but they're at least well-defined concepts. This feels like we're hacking in the things we want to reset for a single use case. But maybe I'm being too picky. We had a similar discussion in PR #18437, which was never fully resolved. So I think we should at least try and make sure that what we're doing here is also going to work for that use case, so we can share the functionality if possible. I'm also a little worried about how this is going to interact with the conhost state. If we're resetting Windows Terminal, but not resetting conhost, are they not going to end up out of sync now? Do we not have a way to pass that reset through somehow? This is maybe less of an issue with the new conpty, but it could still affect shells that rely on the legacy console APIs. I might be overthinking things though. If you're doing a reset, the terminal is assumedly messed up already, so an imperfect fix is probably better than nothing. And assuming we do want to keep this |
|
Took a look at Dustin's and James' feedback in this tread as well as PR #18437 and issue #18425. General overviewI'm starting by writing this here because it gives a good overview of what
From looking through these and reading Copilot's report, here's my breakdown:
Let me know what you all think. At least here it's all listed out, but I'm sure you'll think of interesting corner cases haha 😅. Dustin's comment
Fixed all of these 😊
The concern here is that the old app wrote a partial escape sequence before dying. I can remove it if you think that's not really valid though. James' comment
Took a look at PR #18437. The new I'm going to lean hard on your second paragraph above haha. I'm hoping we can figure out how to make this partial hard reset concept work, but if not, I guess we could do just a plain hard reset? I'm just hesitant to do that because then you lose the buffer contents, and I think that's worth advocating for. Hopefully the list above helps figure out what works and what doesn't.
So, in
I think we're good then because we're creating a new ConPTY process, so there's no stale conhost to get out of sync with. That said, let me know if I'm missing something.
Added 👍 old PR - fixing issue w/ re-entry "Ctrl+D or Enter" message
I looked into this a bit. To make the reset happen before the exit message (printed in
The nice thing with the current approach is that we do retain scrollback. More just including this quote for completeness. |
|
@carlos-zamora Thanks for the detailed write up. I think I'm convinced now that this is a good solution. It does seem reasonable to reset everything in that table, and just preserve the screen/scrollback. And I didn't initially realise we were getting a completely new connection here, so my conhost concerns were nonsense. +1 from me. |
|
I think you were right, though, James, about the conhost thing. We're starting a new connection with an existing buffer, which I think means we need to pass |
|
As for the "Press ^D" message... it's always been my goal (soft goal, I guess) to make that a passive TerminalControl UI element rather than rendering it to the display surface. Alas, the to-do list is longer than I'd like |
Oh! Looks like we're good on that end:
That last |
|
then perhaps all that's left to do is update the description to match the new implementation |
|
Done 😊 |
## Summary of the Pull Request I was becoming frustrated with getting in a state where a CLI app (i.e. Copilot CLI) enters some VT state (like mouse mode) then doesn't unset it when it accidentally exits. I normally use "Restart connection" to keep the buffer and connect again. Problem is, "restart connection" didn't actually reset the internal state! So I would type and get a bunch of lingering VT escape sequences. This bug is tracked over in #18425 in a more generic way. This fixes that bug by doing the following: - update `ITermDispatch::HardReset()` -->`HardReset(bool erase)` - `erase=true` does what `HardReset()` already did - `erase=false` skips over clearing the screen and resetting the cursor position - expose `HardReset(false)` as `HardResetWithoutErase()` by piping it up through `Terminal` --> `ControlCore` --> `TermControl` - update the restart connection handler - `TerminalPage::_restartPaneConnection()` now calls `HardResetWithoutErase()` before setting the new connection - this is also the same route for the "Enter to restart connection" scenario (text displayed when connection ends) Relevant notes from PR discussion: - `PSEUDOCONSOLE_INHERIT_CURSOR` is passed into the new connection via `_restartPaneConnection()` --> `_duplicateConnectionForRestart()` --> `_CreateConnectionFromSettings(profile, *controlSettings.DefaultSettings(), true)` ## Validation Steps Performed - Used this to enter mouse tracking mode: `Write-Host -NoNewline "`e[?1003h`e[?1006h"` - mouse selection doesn't work as usual (expected) - invoke "restart connection" action - mouse selection works as usual Closes #18425 (cherry picked from commit ec939aa) Service-Card-Id: PVTI_lADOAF3p4s4BQX0-zgpBL5s Service-Version: 1.25
## Summary of the Pull Request I was becoming frustrated with getting in a state where a CLI app (i.e. Copilot CLI) enters some VT state (like mouse mode) then doesn't unset it when it accidentally exits. I normally use "Restart connection" to keep the buffer and connect again. Problem is, "restart connection" didn't actually reset the internal state! So I would type and get a bunch of lingering VT escape sequences. This bug is tracked over in #18425 in a more generic way. This fixes that bug by doing the following: - update `ITermDispatch::HardReset()` -->`HardReset(bool erase)` - `erase=true` does what `HardReset()` already did - `erase=false` skips over clearing the screen and resetting the cursor position - expose `HardReset(false)` as `HardResetWithoutErase()` by piping it up through `Terminal` --> `ControlCore` --> `TermControl` - update the restart connection handler - `TerminalPage::_restartPaneConnection()` now calls `HardResetWithoutErase()` before setting the new connection - this is also the same route for the "Enter to restart connection" scenario (text displayed when connection ends) Relevant notes from PR discussion: - `PSEUDOCONSOLE_INHERIT_CURSOR` is passed into the new connection via `_restartPaneConnection()` --> `_duplicateConnectionForRestart()` --> `_CreateConnectionFromSettings(profile, *controlSettings.DefaultSettings(), true)` ## Validation Steps Performed - Used this to enter mouse tracking mode: `Write-Host -NoNewline "`e[?1003h`e[?1006h"` - mouse selection doesn't work as usual (expected) - invoke "restart connection" action - mouse selection works as usual Closes #18425 (cherry picked from commit ec939aa) Service-Card-Id: PVTI_lADOAF3p4s4BBcTlzgpBL5w Service-Version: 1.24
Summary of the Pull Request
I was becoming frustrated with getting in a state where a CLI app (i.e. Copilot CLI) enters some VT state (like mouse mode) then doesn't unset it when it accidentally exits. I normally use "Restart connection" to keep the buffer and connect again. Problem is, "restart connection" didn't actually reset the internal state! So I would type and get a bunch of lingering VT escape sequences. This bug is tracked over in #18425 in a more generic way.
This fixes that bug by doing the following:
ITermDispatch::HardReset()-->HardReset(bool erase)erase=truedoes whatHardReset()already diderase=falseskips over clearing the screen and resetting the cursor positionHardReset(false)asHardResetWithoutErase()by piping it up throughTerminal-->ControlCore-->TermControlTerminalPage::_restartPaneConnection()now callsHardResetWithoutErase()before setting the new connectionRelevant notes from PR discussion:
PSEUDOCONSOLE_INHERIT_CURSORis passed into the new connection via_restartPaneConnection()-->_duplicateConnectionForRestart()-->_CreateConnectionFromSettings(profile, *controlSettings.DefaultSettings(), true)Validation Steps Performed
Write-Host -NoNewline "e[?1003he[?1006h"Closes #18425