Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Always flush conpty before passing-thru a sequence we didn't understand #13462

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion src/host/screenInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2349,8 +2349,20 @@ void SCREEN_INFORMATION::SetTerminalConnection(_In_ VtEngine* const pTtyConnecti
auto& engine = reinterpret_cast<OutputStateMachineEngine&>(_stateMachine->Engine());
if (pTtyConnection)
{
// GH#8698: When the state machine encounters a string that adapt
// dispatch couldn't handle, and we're in conpty, we should:
// - 1. Flush the current conpty frame
// - 2. write the unhandled sequence to the terminal side.
//
// This will make sure that anything we've currently buffered is
// processed by the terminal, before we pass through the thing we don't
// recognize. That way, the terminal will have the full state of
// whatever sequences came before the thing we didn't understand.
engine.SetTerminalConnection(pTtyConnection,
std::bind(&StateMachine::FlushToTerminal, _stateMachine.get()));
[this]() -> bool {
ServiceLocator::LocateGlobals().pRender->TriggerFlush(false);
return _stateMachine->FlushToTerminal();
});
}
else
{
Expand Down
14 changes: 9 additions & 5 deletions src/terminal/adapter/adaptDispatch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2480,8 +2480,9 @@ bool AdaptDispatch::DoITerm2Action(const std::wstring_view string)
// This is not implemented in conhost.
if (_api.IsConsolePty())
{
// Flush the frame manually, to make sure marks end up on the right line, like the alt buffer sequence.
_renderer.TriggerFlush(false);
// As of GH#8698, when we return false in ConPTY mode, we'll
// automatically flush the currently buffered frame before passing
// through this sequence.
return false;
Comment on lines +2500 to 2503
Copy link
Collaborator

Choose a reason for hiding this comment

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

It seems to me that these comments are somewhat misleading, since they suggest that these three places are unique in the way they flush the current frame, when in fact it applies to everywhere we're returning false. The only thing special about these cases is that they were historically the only ones that used to work, but I don't think that information is particularly useful going forward is it?

}

Expand Down Expand Up @@ -2524,8 +2525,9 @@ bool AdaptDispatch::DoFinalTermAction(const std::wstring_view string)
// This is not implemented in conhost.
if (_api.IsConsolePty())
{
// Flush the frame manually, to make sure marks end up on the right line, like the alt buffer sequence.
_renderer.TriggerFlush(false);
// As of GH#8698, when we return false in ConPTY mode, we'll
// automatically flush the currently buffered frame before passing
// through this sequence.
return false;
}

Expand Down Expand Up @@ -2869,7 +2871,9 @@ bool AdaptDispatch::PlaySounds(const VTParameters parameters)
// first, otherwise the visual output will lag behind the sound.
if (_api.IsConsolePty())
{
_renderer.TriggerFlush(false);
// As of GH#8698, when we return false in ConPTY mode, we'll
// automatically flush the currently buffered frame before passing
// through this sequence.
return false;
}

Expand Down