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

Use VT for COOKED_READ_DATA #17445

Merged
merged 24 commits into from
Jul 11, 2024
Merged
Changes from 1 commit
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
bbbe20f
Move colorbrewer into its own proper header
lhecker Jun 19, 2024
b0cc432
Use VT for COOKED_READ_DATA
lhecker Jun 19, 2024
e08ebbe
Fix GetVirtualViewport, Fix popup alignment
lhecker Jun 20, 2024
88ef5f4
Address feedback
lhecker Jun 20, 2024
413991e
Address feedback, Fix scrolling bug
lhecker Jun 21, 2024
8688a50
Merge remote-tracking branch 'origin/main' into dev/lhecker/14000-vt-…
lhecker Jun 21, 2024
32a1249
Fix several issues with control character visualizers
lhecker Jun 25, 2024
4471e98
Fix ambiguous chars, Improve F7+F9 UX
lhecker Jun 25, 2024
0e63bd0
Merge remote-tracking branch 'origin/main' into dev/lhecker/14000-vt-…
lhecker Jun 25, 2024
8f39b49
Overkill initialData impl, but hopefully not kill
lhecker Jun 25, 2024
b6e4046
Fix break not breaking, Fix column not columning
lhecker Jun 25, 2024
671f371
C++ cast
lhecker Jun 25, 2024
e5b8f5b
Fix cursor position after reflow
lhecker Jul 1, 2024
567260e
Fix prompt boundaries after wrapping
lhecker Jul 1, 2024
4cda975
Fix _viewport size after shrinking
lhecker Jul 1, 2024
398d795
More robust bodgy reflow hacks
lhecker Jul 2, 2024
2fe302c
Merge remote-tracking branch 'origin/main' into dev/lhecker/14000-vt-…
lhecker Jul 9, 2024
a63b806
Address feedback, Add comments, Update formatAttributes
lhecker Jul 9, 2024
8116d5b
Address j4james' feedback from the other PR
lhecker Jul 9, 2024
1f5dc90
Fix buffer invalidation
lhecker Jul 9, 2024
8c7cf58
Oh, right, we support graphemes
lhecker Jul 9, 2024
b3f11d5
Fix formatAttributes
lhecker Jul 9, 2024
08f3bac
Forgot to finish this
lhecker Jul 9, 2024
dc8ac1d
Improve comments, resize_and_overwrite is terrible
lhecker Jul 11, 2024
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
Prev Previous commit
Next Next commit
Fix GetVirtualViewport, Fix popup alignment
lhecker committed Jun 20, 2024
commit e08ebbe570ba32c6fd5ef3bf4ac4090f321ac6ab
24 changes: 9 additions & 15 deletions src/host/readDataCooked.cpp
Original file line number Diff line number Diff line change
@@ -110,7 +110,7 @@ COOKED_READ_DATA::COOKED_READ_DATA(_In_ InputBuffer* const pInputBuffer,
absoluteCursorPos.y = gsl::narrow_cast<til::CoordType>(cols / w);
}

_screenInfo.GetVirtualViewport().ConvertToOrigin(&absoluteCursorPos);
_screenInfo.GetVirtualBufferViewport().ConvertToOrigin(&absoluteCursorPos);
absoluteCursorPos.x = std::max(0, absoluteCursorPos.x);
absoluteCursorPos.y = std::max(0, absoluteCursorPos.y);

@@ -259,7 +259,7 @@ bool COOKED_READ_DATA::PresentingPopup() const noexcept
til::point_span COOKED_READ_DATA::GetBoundaries() const noexcept
{
const auto viewport = _screenInfo.GetViewport();
const auto virtualViewport = _screenInfo.GetVirtualViewport();
const auto virtualViewport = _screenInfo.GetVirtualBufferViewport();

static constexpr til::point min;
const til::point max{ viewport.RightInclusive(), viewport.BottomInclusive() };
@@ -777,7 +777,7 @@ void COOKED_READ_DATA::_redisplay()
return;
}

const auto size = _screenInfo.GetVirtualViewport().Dimensions();
const auto size = _screenInfo.GetBufferSize().Dimensions();
auto originInViewportFinal = _originInViewport;
til::point cursorPositionFinal;
til::point pagerPromptEnd;
@@ -868,16 +868,11 @@ void COOKED_READ_DATA::_redisplay()
{
auto& popup = _popups.back();

// But it should not be right on the line where the prompt starts.
// That would look goofy otherwise, since there's where the text is supposed to go.
if (lines.empty())
{
lines.emplace_back();
}

// Ensure that the popup is not considered part of the prompt line. That is, if someone double-clicks
// to select the last word in the prompt, it should not select the first word in the popup.
lines.back().text.append(L"\r\n");
auto& lastLine = lines.back();
lastLine.text.append(L"\r\n");
lastLine.columns = size.width;

switch (popup.kind)
{
@@ -913,7 +908,7 @@ void COOKED_READ_DATA::_redisplay()
// a line because otherwise it won't have any space to be visible.
if (_bufferCursor == _buffer.size())
{
lines.emplace_back(L" \b");
lines.emplace_back(L" \b", 0, 0, 0);
}
}

@@ -1383,7 +1378,7 @@ void COOKED_READ_DATA::_popupDrawPrompt(std::vector<Line>& lines, const til::siz
const auto res = _layoutLine(line, str, 0, 0, size.width);
line.append(L"\x1b[m");

lines.emplace_back(std::move(line), 0, res.column);
lines.emplace_back(std::move(line), 0, 0, res.column);
}

void COOKED_READ_DATA::_popupDrawCommandList(std::vector<Line>& lines, const til::size size, Popup& popup) const
@@ -1467,7 +1462,6 @@ void COOKED_READ_DATA::_popupDrawCommandList(std::vector<Line>& lines, const til
if (res.offset < str.size())
{
line.push_back(L'…');
res.column++;
}

if (selected)
@@ -1476,7 +1470,7 @@ void COOKED_READ_DATA::_popupDrawCommandList(std::vector<Line>& lines, const til
}

line.append(L"\r\n");
lines.emplace_back(std::move(line), 0, 0, res.column);
lines.emplace_back(std::move(line), 0, 0, size.width);
}

auto& lastLine = lines.back();
20 changes: 12 additions & 8 deletions src/host/screenInfo.cpp
Original file line number Diff line number Diff line change
@@ -2451,20 +2451,24 @@ void SCREEN_INFORMATION::UpdateBottom()
_virtualBottom = _viewport.BottomInclusive();
}

// Method Description:
// - Returns the "virtual" Viewport - the viewport with its bottom at
// `_virtualBottom`. For VT operations, this is essentially the mutable
// section of the buffer.
// Arguments:
// - <none>
// Return Value:
// - the virtual terminal viewport
// Returns the section of the text buffer that would be visible on the screen
// if the user didn't scroll away vertically. It's essentially the same as
// GetVirtualBufferViewport() but includes the horizontal scroll offset.
Viewport SCREEN_INFORMATION::GetVirtualViewport() const noexcept
{
const auto newTop = _virtualBottom - _viewport.Height() + 1;
return Viewport::FromDimensions({ _viewport.Left(), newTop }, _viewport.Dimensions());
}

// Returns the section of the text buffer that's addressable by VT sequences.
Viewport SCREEN_INFORMATION::GetVirtualBufferViewport() const noexcept
{
const auto viewportHeight = _viewport.Height();
const auto bufferWidth = _textBuffer->GetSize().Width();
const auto top = std::max(0, _virtualBottom - viewportHeight + 1);
return Viewport::FromExclusive({ 0, top, bufferWidth, top + viewportHeight });
}

// Method Description:
// - Returns true if the character at the cursor's current position is wide.
// See IsGlyphFullWidth
1 change: 1 addition & 0 deletions src/host/screenInfo.hpp
Original file line number Diff line number Diff line change
@@ -115,6 +115,7 @@ class SCREEN_INFORMATION : public ConsoleObjectHeader, public Microsoft::Console
const Microsoft::Console::Types::Viewport& GetViewport() const noexcept;
void SetViewport(const Microsoft::Console::Types::Viewport& newViewport, const bool updateBottom);
Microsoft::Console::Types::Viewport GetVirtualViewport() const noexcept;
Microsoft::Console::Types::Viewport GetVirtualBufferViewport() const noexcept;

void ProcessResizeWindow(const til::rect* const prcClientNew, const til::rect* const prcClientOld);
void SetViewportSize(const til::size* const pcoordSize);