-
Notifications
You must be signed in to change notification settings - Fork 8.5k
Improve reliability of VT responses #17786
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -98,7 +98,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation | |
Connection(connection); | ||
|
||
_terminal->SetWriteInputCallback([this](std::wstring_view wstr) { | ||
_sendInputToConnection(wstr); | ||
_pendingResponses.append(wstr); | ||
}); | ||
|
||
// GH#8969: pre-seed working directory to prevent potential races | ||
|
@@ -419,6 +419,20 @@ namespace winrt::Microsoft::Terminal::Control::implementation | |
// Return Value: | ||
// - <none> | ||
void ControlCore::_sendInputToConnection(std::wstring_view wstr) | ||
{ | ||
if (!wstr.empty()) | ||
{ | ||
_connection.WriteInput(winrt_wstring_to_array_view(wstr)); | ||
} | ||
} | ||
|
||
// Method Description: | ||
// - Writes the given sequence as input to the active terminal connection, | ||
// Arguments: | ||
// - wstr: the string of characters to write to the terminal connection. | ||
// Return Value: | ||
// - <none> | ||
void ControlCore::SendInput(const std::wstring_view wstr) | ||
{ | ||
if (wstr.empty()) | ||
{ | ||
|
@@ -435,21 +449,10 @@ namespace winrt::Microsoft::Terminal::Control::implementation | |
} | ||
else | ||
{ | ||
_connection.WriteInput(winrt_wstring_to_array_view(wstr)); | ||
_sendInputToConnection(wstr); | ||
} | ||
} | ||
|
||
// Method Description: | ||
// - Writes the given sequence as input to the active terminal connection, | ||
// Arguments: | ||
// - wstr: the string of characters to write to the terminal connection. | ||
// Return Value: | ||
// - <none> | ||
void ControlCore::SendInput(const std::wstring_view wstr) | ||
{ | ||
_sendInputToConnection(wstr); | ||
} | ||
|
||
bool ControlCore::SendCharEvent(const wchar_t ch, | ||
const WORD scanCode, | ||
const ::Microsoft::Terminal::Core::ControlKeyStates modifiers) | ||
|
@@ -485,7 +488,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation | |
} | ||
if (out) | ||
{ | ||
_sendInputToConnection(*out); | ||
SendInput(*out); | ||
return true; | ||
} | ||
return false; | ||
|
@@ -643,7 +646,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation | |
} | ||
if (out) | ||
{ | ||
_sendInputToConnection(*out); | ||
SendInput(*out); | ||
return true; | ||
} | ||
return false; | ||
|
@@ -662,7 +665,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation | |
} | ||
if (out) | ||
{ | ||
_sendInputToConnection(*out); | ||
SendInput(*out); | ||
return true; | ||
} | ||
return false; | ||
|
@@ -1412,7 +1415,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation | |
} | ||
|
||
// It's important to not hold the terminal lock while calling this function as sending the data may take a long time. | ||
_sendInputToConnection(filtered); | ||
SendInput(filtered); | ||
|
||
const auto lock = _terminal->LockForWriting(); | ||
_terminal->ClearSelection(); | ||
|
@@ -2107,7 +2110,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation | |
// Sending input requires that we're unlocked, because | ||
// writing the input pipe may block indefinitely. | ||
const auto suspension = _terminal->SuspendLock(); | ||
_sendInputToConnection(buffer); | ||
SendInput(buffer); | ||
} | ||
} | ||
} | ||
|
@@ -2164,6 +2167,12 @@ namespace winrt::Microsoft::Terminal::Control::implementation | |
_terminal->Write(hstr); | ||
} | ||
|
||
if (!_pendingResponses.empty()) | ||
{ | ||
_sendInputToConnection(_pendingResponses); | ||
_pendingResponses.clear(); | ||
} | ||
Comment on lines
+2167
to
+2171
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This fixes the bug. It also fixes 2nd bug: We'd previously use the old There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. oh this is clever. it replies with it immediately after the write that caused a reply? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah exactly. This is much better than before, because it's now processing an entire VT string atomically without unlocking in between. Not sure why I haven't done this from the get-go. |
||
|
||
// Start the throttled update of where our hyperlinks are. | ||
const auto shared = _shared.lock_shared(); | ||
if (shared->outputIdle) | ||
|
@@ -2480,9 +2489,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation | |
} | ||
if (out && !out->empty()) | ||
{ | ||
// _sendInputToConnection() asserts that we aren't in focus mode, | ||
// but window focus events are always fine to send. | ||
_connection.WriteInput(winrt_wstring_to_array_view(*out)); | ||
_sendInputToConnection(*out); | ||
} | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SendInput
now does what_sendInputToConnection
previously did._sendInputToConnection
is now a write-directly-to-connection function.