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

Fix cooked read reflow under ConPTY #17668

Merged
merged 1 commit into from
Aug 7, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
23 changes: 19 additions & 4 deletions src/host/readDataCooked.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -295,10 +295,14 @@ void COOKED_READ_DATA::EraseBeforeResize()

_redrawPending = true;

std::wstring output;
_appendCUP(output, _originInViewport);
output.append(L"\x1b[J");
WriteCharsVT(_screenInfo, output);
// Position the cursor the start of the prompt before reflow.
// Then, after reflow, we'll be able to ask the buffer where it went (the new origin).
// This uses the buffer APIs directly, so that we don't emit unnecessary VT into ConPTY's output.
auto& textBuffer = _screenInfo.GetTextBuffer();
auto& cursor = textBuffer.GetCursor();
auto cursorPos = _originInViewport;
_screenInfo.GetVtPageArea().ConvertFromOrigin(&cursorPos);
cursor.SetPosition(cursorPos);
}

// The counter-part to EraseBeforeResize().
Expand All @@ -322,6 +326,10 @@ void COOKED_READ_DATA::RedrawAfterResize()
_bufferDirtyBeg = 0;
_dirty = !_buffer.empty();

// Let _redisplay() know to inject a CSI J at the start of the output.
// This ensures we fully erase the previous contents, that are now in disarray.
_clearPending = true;

_redisplay();
}

Expand Down Expand Up @@ -1081,6 +1089,13 @@ void COOKED_READ_DATA::_redisplay()

std::wstring output;

if (_clearPending)
{
_clearPending = false;
_appendCUP(output, _originInViewport);
output.append(L"\x1b[J");
}

// Disable the cursor when opening a popup, reenable it when closing them.
if (const auto popupOpened = !_popups.empty(); _popupOpened != popupOpened)
{
Expand Down
1 change: 1 addition & 0 deletions src/host/readDataCooked.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ class COOKED_READ_DATA final : public ReadData
bool _insertMode = false;
bool _dirty = false;
bool _redrawPending = false;
bool _clearPending = false;

til::point _originInViewport;
// This value is in the pager coordinate space. (0,0) is the first character of the
Expand Down
Loading