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

Add support for VT paging operations #16615

Merged
merged 21 commits into from
May 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
5ae9884
Hook up the paging escape sequences.
j4james Jan 16, 2024
6b43e44
Add api returning both buffer and viewport.
j4james Jan 20, 2024
8c1fd66
Add class for managing VT page buffers.
j4james Jan 25, 2024
af6fd19
Integrate page manager into AdaptDispatch.
j4james Jan 25, 2024
e451c5b
Remove unused ITerminalApi methods.
j4james Jan 25, 2024
22535b0
Add support for page cursor coupling mode.
j4james Jan 25, 2024
7046768
Add support for DECRQDE query.
j4james Jan 25, 2024
bdb890f
Use Page instead of TextBuffer in more AdaptDispatch methods.
j4james Jan 25, 2024
f82f40d
Handle cursor and attribute access through Page object.
j4james Jan 25, 2024
15a7c46
Get buffer/viewport dimensions through Page object.
j4james Jan 26, 2024
79f26f5
Add some terms to spellbot dictionary.
j4james Jan 28, 2024
6ded041
Correct viewport positioning on background pages.
j4james Jan 30, 2024
293a73f
Use struct in place of tuple.
j4james Jan 30, 2024
69e2037
Eliminate some unnecessary textbuffer locals.
j4james Jan 30, 2024
b35d5ed
Add some more comments.
j4james Jan 30, 2024
d452725
Only propagate ED2 through conpty for the active buffer.
j4james Feb 18, 2024
c5d0c12
Update the DECXCPR test to check the page number.
j4james Mar 7, 2024
14de021
Add some unit tests for the new paging operations.
j4james Mar 9, 2024
e25d792
Merge branch 'main' into feature-paging
j4james May 2, 2024
2488e9a
Replace obsolete GetTextBuffer api calls.
j4james May 2, 2024
7795bab
Merge branch 'main' into feature-paging
j4james May 8, 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
4 changes: 4 additions & 0 deletions .github/actions/spelling/expect/expect.txt
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,7 @@
DECNRCM
DECOM
decommit
DECPCCM
DECPCTERM
DECPS
DECRARA
Expand All @@ -414,6 +415,7 @@
DECRLM
DECRPM
DECRQCRA
DECRQDE
DECRQM
DECRQPSR
DECRQSS
Expand Down Expand Up @@ -780,7 +782,7 @@
Hostx
HPA
hpcon
HPCON

Check warning on line 785 in .github/actions/spelling/expect/expect.txt

View workflow job for this annotation

GitHub Actions / Spell checking

`HPCON` is ignored by check spelling because another more general variant is also in expect. (ignored-expect-variant)
hpen
HPR
HProvider
Expand Down Expand Up @@ -2123,6 +2125,7 @@
XManifest
XMath
xorg
XPan
XResource
xsi
xstyler
Expand All @@ -2142,6 +2145,7 @@
YCENTER
YCount
YLimit
YPan
YSubstantial
YVIRTUALSCREEN
YWalk
Expand Down
3 changes: 1 addition & 2 deletions src/cascadia/TerminalCore/Terminal.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,7 @@ class Microsoft::Terminal::Core::Terminal final :
// These methods are defined in TerminalApi.cpp
void ReturnResponse(const std::wstring_view response) override;
Microsoft::Console::VirtualTerminal::StateMachine& GetStateMachine() noexcept override;
TextBuffer& GetTextBuffer() noexcept override;
til::rect GetViewport() const noexcept override;
BufferState GetBufferAndViewport() noexcept override;
void SetViewportPosition(const til::point position) noexcept override;
void SetTextAttributes(const TextAttribute& attrs) noexcept override;
void SetSystemMode(const Mode mode, const bool enabled) noexcept override;
Expand Down
9 changes: 2 additions & 7 deletions src/cascadia/TerminalCore/TerminalApi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,9 @@ Microsoft::Console::VirtualTerminal::StateMachine& Terminal::GetStateMachine() n
return *_stateMachine;
}

TextBuffer& Terminal::GetTextBuffer() noexcept
ITerminalApi::BufferState Terminal::GetBufferAndViewport() noexcept
{
return _activeBuffer();
}

til::rect Terminal::GetViewport() const noexcept
{
return til::rect{ _GetMutableViewport().ToInclusive() };
return { _activeBuffer(), til::rect{ _GetMutableViewport().ToInclusive() }, !_inAltBuffer() };
}

void Terminal::SetViewportPosition(const til::point position) noexcept
Expand Down
23 changes: 14 additions & 9 deletions src/cascadia/UnitTests_TerminalCore/SelectionTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ namespace TerminalCoreUnitTests
VERIFY_ARE_EQUAL(selection, expected);
}

TextBuffer& GetTextBuffer(Terminal& term)
{
return term.GetBufferAndViewport().buffer;
}

TEST_METHOD(SelectUnit)
{
Terminal term{ Terminal::TestDummyMarker{} };
Expand Down Expand Up @@ -394,7 +399,7 @@ namespace TerminalCoreUnitTests
const auto burrito = L"\xD83C\xDF2F";

// Insert wide glyph at position (4,10)
term.GetTextBuffer().GetCursor().SetPosition({ 4, 10 });
GetTextBuffer(term).GetCursor().SetPosition({ 4, 10 });
term.Write(burrito);

// Simulate click at (x,y) = (5,10)
Expand All @@ -417,7 +422,7 @@ namespace TerminalCoreUnitTests
const auto burrito = L"\xD83C\xDF2F";

// Insert wide glyph at position (4,10)
term.GetTextBuffer().GetCursor().SetPosition({ 4, 10 });
GetTextBuffer(term).GetCursor().SetPosition({ 4, 10 });
term.Write(burrito);

// Simulate click at (x,y) = (5,10)
Expand All @@ -440,11 +445,11 @@ namespace TerminalCoreUnitTests
const auto burrito = L"\xD83C\xDF2F";

// Insert wide glyph at position (4,10)
term.GetTextBuffer().GetCursor().SetPosition({ 4, 10 });
GetTextBuffer(term).GetCursor().SetPosition({ 4, 10 });
term.Write(burrito);

// Insert wide glyph at position (7,11)
term.GetTextBuffer().GetCursor().SetPosition({ 7, 11 });
GetTextBuffer(term).GetCursor().SetPosition({ 7, 11 });
term.Write(burrito);

// Simulate ALT + click at (x,y) = (5,8)
Expand Down Expand Up @@ -496,7 +501,7 @@ namespace TerminalCoreUnitTests

// Insert text at position (4,10)
const std::wstring_view text = L"doubleClickMe";
term.GetTextBuffer().GetCursor().SetPosition({ 4, 10 });
GetTextBuffer(term).GetCursor().SetPosition({ 4, 10 });
term.Write(text);

// Simulate double click at (x,y) = (5,10)
Expand Down Expand Up @@ -540,7 +545,7 @@ namespace TerminalCoreUnitTests

// Insert text at position (4,10)
const std::wstring_view text = L"C:\\Terminal>";
term.GetTextBuffer().GetCursor().SetPosition({ 4, 10 });
GetTextBuffer(term).GetCursor().SetPosition({ 4, 10 });
term.Write(text);

// Simulate click at (x,y) = (15,10)
Expand Down Expand Up @@ -568,7 +573,7 @@ namespace TerminalCoreUnitTests

// Insert text at position (4,10)
const std::wstring_view text = L"doubleClickMe dragThroughHere";
term.GetTextBuffer().GetCursor().SetPosition({ 4, 10 });
GetTextBuffer(term).GetCursor().SetPosition({ 4, 10 });
term.Write(text);

// Simulate double click at (x,y) = (5,10)
Expand Down Expand Up @@ -597,7 +602,7 @@ namespace TerminalCoreUnitTests

// Insert text at position (21,10)
const std::wstring_view text = L"doubleClickMe dragThroughHere";
term.GetTextBuffer().GetCursor().SetPosition({ 4, 10 });
GetTextBuffer(term).GetCursor().SetPosition({ 4, 10 });
term.Write(text);

// Simulate double click at (x,y) = (21,10)
Expand Down Expand Up @@ -685,7 +690,7 @@ namespace TerminalCoreUnitTests

// Insert text at position (4,10)
const std::wstring_view text = L"doubleClickMe dragThroughHere";
term.GetTextBuffer().GetCursor().SetPosition({ 4, 10 });
GetTextBuffer(term).GetCursor().SetPosition({ 4, 10 });
term.Write(text);

// Step 1: Create a selection on "doubleClickMe"
Expand Down
3 changes: 2 additions & 1 deletion src/cascadia/UnitTests_TerminalCore/TerminalApiTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,8 @@ void TerminalApiTest::CursorVisibility()
VERIFY_IS_TRUE(term._mainBuffer->GetCursor().IsOn());
VERIFY_IS_TRUE(term._mainBuffer->GetCursor().IsBlinkingAllowed());

term.GetTextBuffer().GetCursor().SetIsVisible(false);
auto& textBuffer = term.GetBufferAndViewport().buffer;
textBuffer.GetCursor().SetIsVisible(false);
VERIFY_IS_FALSE(term._mainBuffer->GetCursor().IsVisible());
VERIFY_IS_TRUE(term._mainBuffer->GetCursor().IsOn());
VERIFY_IS_TRUE(term._mainBuffer->GetCursor().IsBlinkingAllowed());
Expand Down
21 changes: 6 additions & 15 deletions src/host/outputStream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,25 +52,16 @@ StateMachine& ConhostInternalGetSet::GetStateMachine()
}

// Routine Description:
// - Retrieves the text buffer for the active output buffer.
// - Retrieves the text buffer and virtual viewport for the active output
// buffer. Also returns a flag indicating whether it's the main buffer.
// Arguments:
// - <none>
// Return Value:
// - a reference to the TextBuffer instance.
TextBuffer& ConhostInternalGetSet::GetTextBuffer()
// - a tuple with the buffer reference, viewport, and main buffer flag.
ITerminalApi::BufferState ConhostInternalGetSet::GetBufferAndViewport()
{
return _io.GetActiveOutputBuffer().GetTextBuffer();
}

// Routine Description:
// - Retrieves the virtual viewport of the active output buffer.
// Arguments:
// - <none>
// Return Value:
// - the exclusive coordinates of the viewport.
til::rect ConhostInternalGetSet::GetViewport() const
{
return _io.GetActiveOutputBuffer().GetVirtualViewport().ToExclusive();
auto& info = _io.GetActiveOutputBuffer();
return { info.GetTextBuffer(), info.GetVirtualViewport().ToExclusive(), info.Next == nullptr };
}

// Routine Description:
Expand Down
3 changes: 1 addition & 2 deletions src/host/outputStream.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ class ConhostInternalGetSet final : public Microsoft::Console::VirtualTerminal::
void ReturnResponse(const std::wstring_view response) override;

Microsoft::Console::VirtualTerminal::StateMachine& GetStateMachine() override;
TextBuffer& GetTextBuffer() override;
til::rect GetViewport() const override;
BufferState GetBufferAndViewport() override;
void SetViewportPosition(const til::point position) override;

void SetTextAttributes(const TextAttribute& attrs) override;
Expand Down
1 change: 1 addition & 0 deletions src/terminal/adapter/DispatchTypes.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -531,6 +531,7 @@ namespace Microsoft::Console::VirtualTerminal::DispatchTypes
ATT610_StartCursorBlink = DECPrivateMode(12),
DECTCEM_TextCursorEnableMode = DECPrivateMode(25),
XTERM_EnableDECCOLMSupport = DECPrivateMode(40),
DECPCCM_PageCursorCouplingMode = DECPrivateMode(64),
DECNKM_NumericKeypadMode = DECPrivateMode(66),
DECBKM_BackarrowKeyMode = DECPrivateMode(67),
DECLRMM_LeftRightMarginMode = DECPrivateMode(69),
Expand Down
6 changes: 6 additions & 0 deletions src/terminal/adapter/ITermDispatch.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,12 @@ class Microsoft::Console::VirtualTerminal::ITermDispatch
virtual bool DeleteCharacter(const VTInt count) = 0; // DCH
virtual bool ScrollUp(const VTInt distance) = 0; // SU
virtual bool ScrollDown(const VTInt distance) = 0; // SD
virtual bool NextPage(const VTInt pageCount) = 0; // NP
virtual bool PrecedingPage(const VTInt pageCount) = 0; // PP
virtual bool PagePositionAbsolute(const VTInt page) = 0; // PPA
virtual bool PagePositionRelative(const VTInt pageCount) = 0; // PPR
virtual bool PagePositionBack(const VTInt pageCount) = 0; // PPB
virtual bool RequestDisplayedExtent() = 0; // DECRQDE
virtual bool InsertLine(const VTInt distance) = 0; // IL
virtual bool DeleteLine(const VTInt distance) = 0; // DL
virtual bool InsertColumn(const VTInt distance) = 0; // DECIC
Expand Down
10 changes: 8 additions & 2 deletions src/terminal/adapter/ITerminalApi.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,15 @@ namespace Microsoft::Console::VirtualTerminal

virtual void ReturnResponse(const std::wstring_view response) = 0;

struct BufferState
{
TextBuffer& buffer;
til::rect viewport;
bool isMainBuffer;
};

virtual StateMachine& GetStateMachine() = 0;
virtual TextBuffer& GetTextBuffer() = 0;
virtual til::rect GetViewport() const = 0;
virtual BufferState GetBufferAndViewport() = 0;
virtual void SetViewportPosition(const til::point position) = 0;

virtual bool IsVtInputEnabled() const = 0;
Expand Down
4 changes: 2 additions & 2 deletions src/terminal/adapter/InteractDispatch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ bool InteractDispatch::WindowManipulation(const DispatchTypes::WindowManipulatio
_api.ShowWindow(false);
return true;
case DispatchTypes::WindowManipulationType::RefreshWindow:
_api.GetTextBuffer().TriggerRedrawAll();
_api.GetBufferAndViewport().buffer.TriggerRedrawAll();
return true;
case DispatchTypes::WindowManipulationType::ResizeWindowInCharacters:
// TODO:GH#1765 We should introduce a better `ResizeConpty` function to
Expand All @@ -135,7 +135,7 @@ bool InteractDispatch::WindowManipulation(const DispatchTypes::WindowManipulatio
bool InteractDispatch::MoveCursor(const VTInt row, const VTInt col)
{
// First retrieve some information about the buffer
const auto viewport = _api.GetViewport();
const auto viewport = _api.GetBufferAndViewport().viewport;

// In VT, the origin is 1,1. For our array, it's 0,0. So subtract 1.
// Apply boundary tests to ensure the cursor isn't outside the viewport rectangle.
Expand Down
Loading
Loading