[PR #14874] [MERGED] Merge the LineFeed functionality into AdaptDispatch #30296

Open
opened 2026-01-31 09:39:54 +00:00 by claunia · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/microsoft/terminal/pull/14874
Author: @j4james
Created: 2/18/2023
Status: Merged
Merged: 3/30/2023
Merged by: @DHowett

Base: mainHead: refactor-linefeed


📝 Commits (10+)

  • 59f9c64 Implement the line feed functionality in AdaptDispatch.
  • 26ebc0a Add API for conhost/terminal specific behavior.
  • b6974f0 Allow for multiple buffer rotation cycles.
  • b8f8ef3 Make sure ED sequence handles buffer rotation correctly.
  • aa93940 Fix unit tests.
  • 5042d82 Removed unused LineFeed API.
  • dbd9ef3 Remove unneeded VT code from AdjustCursorPosition.
  • 1b94985 Remove unneeded margin APIs.
  • 90bd976 Rewrite margin adapter test.
  • d7b3e49 Workaround for removed margin API in screen buffer tests.

📊 Changes

15 files changed (+330 additions, -638 deletions)

View changed files

📝 src/cascadia/TerminalCore/Terminal.cpp (+9 -141)
📝 src/cascadia/TerminalCore/Terminal.hpp (+2 -3)
📝 src/cascadia/TerminalCore/TerminalApi.cpp (+62 -22)
📝 src/cascadia/UnitTests_TerminalCore/ConptyRoundtripTests.cpp (+22 -19)
📝 src/host/_stream.cpp (+1 -189)
📝 src/host/output.cpp (+1 -2)
📝 src/host/outputStream.cpp (+19 -50)
📝 src/host/outputStream.hpp (+1 -3)
📝 src/host/screenInfo.cpp (+0 -60)
📝 src/host/screenInfo.hpp (+0 -8)
📝 src/host/ut_host/ScreenBufferTests.cpp (+31 -8)
📝 src/terminal/adapter/ITerminalApi.hpp (+1 -2)
📝 src/terminal/adapter/adaptDispatch.cpp (+129 -28)
📝 src/terminal/adapter/adaptDispatch.hpp (+5 -3)
📝 src/terminal/adapter/ut_adapter/adapterTest.cpp (+47 -100)

📄 Description

The main purpose of this PR was to merge the ITerminalApi::LineFeed
implementations into a shared method in AdaptDispatch, and avoid the
VT code path depending on the AdjustCursorPosition function (which
could then be massively simplified). This refactoring also fixes some
bugs that existed in the original LineFeed implementations.

References and Relevant Issues

This helps to close the gap between the Conhost and Terminal (#13408).
This improves some of the scrollbar mark bugs mentioned in #11000.

Detailed Description of the Pull Request / Additional comments

I had initially hoped the line feed functionality could be implemented
entirely within AdaptDispatch, but there is still some Conhost and
Terminal-specific behavior that needs to be triggered when we reach the
bottom of the buffer, and the row coordinates are cycled.

In Conhost we need to trigger an accessibility scroll event, and in
Windows Terminal we need to update selection and marker offsets, reset
pattern intervals, and preserve the user's scroll offset. This is now
handled by a new NotifyBufferRotation method in ITerminalApi.

But this made me realise that the _EraseAll method should have been
doing the same thing when it reached the bottom of the buffer. So I've
added a call to the new NotifyBufferRotation API from there as well.

And in the case of Windows Terminal, the scroll offset preservation was
something that was also needed for a regular viewport pan. So I've put
that in a separate _PreserveUserScrollOffset method which is called
from the SetViewportPosition handler as well.

Validation Steps Performed

Because of the API changes, there were a number of unit tests that
needed to be updated:

  • Some of the ScreenBufferTests were accessing margin state in the
    SCREEN_INFORMATION class which doesn't exist anymore, so I had to add
    a little helper function which now manually detects the active margins.

  • Some of the AdapterTest tests were dependent on APIs that no longer
    exist, so they needed to be rewritten so they now check the resulting
    state rather than expecting a mock API call.

  • The ScrollWithMargins test in ConptyRoundtripTests was testing
    functionality that didn't previously work correctly (issue #3673). Now
    that it's been fixed, that test needed to be updated accordingly.

Other than getting the unit tests working, I've manually verified that
issue #3673 is now fixed. And I've also checked that the scroll markers,
selections, and user scroll offset are all being updated correctly, both
with a regular viewport pan, as well as when overrunning the buffer.

Closes #3673


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/microsoft/terminal/pull/14874 **Author:** [@j4james](https://github.com/j4james) **Created:** 2/18/2023 **Status:** ✅ Merged **Merged:** 3/30/2023 **Merged by:** [@DHowett](https://github.com/DHowett) **Base:** `main` ← **Head:** `refactor-linefeed` --- ### 📝 Commits (10+) - [`59f9c64`](https://github.com/microsoft/terminal/commit/59f9c64ad68c3424269813487848881d753e283d) Implement the line feed functionality in AdaptDispatch. - [`26ebc0a`](https://github.com/microsoft/terminal/commit/26ebc0a359a3946698167c6faa6b0717d94f9f98) Add API for conhost/terminal specific behavior. - [`b6974f0`](https://github.com/microsoft/terminal/commit/b6974f0de561825afa8da226b1fb79018d6ef1b9) Allow for multiple buffer rotation cycles. - [`b8f8ef3`](https://github.com/microsoft/terminal/commit/b8f8ef311a3dfc20ff81ea847e885be8da9ff2f5) Make sure ED sequence handles buffer rotation correctly. - [`aa93940`](https://github.com/microsoft/terminal/commit/aa93940da9bfa76e7db648159544cd816365fd5f) Fix unit tests. - [`5042d82`](https://github.com/microsoft/terminal/commit/5042d82b30c9324f7cd70798c7780e763616cd8c) Removed unused LineFeed API. - [`dbd9ef3`](https://github.com/microsoft/terminal/commit/dbd9ef32ed5c79fa15b2f61233286f7566d3d64f) Remove unneeded VT code from AdjustCursorPosition. - [`1b94985`](https://github.com/microsoft/terminal/commit/1b9498563fe432d569bf37860453e446692269d6) Remove unneeded margin APIs. - [`90bd976`](https://github.com/microsoft/terminal/commit/90bd976c753f15bfc2b90d7579df41ce9b2713ef) Rewrite margin adapter test. - [`d7b3e49`](https://github.com/microsoft/terminal/commit/d7b3e494df1fad06a7d19274d43aa3fa577c8ad0) Workaround for removed margin API in screen buffer tests. ### 📊 Changes **15 files changed** (+330 additions, -638 deletions) <details> <summary>View changed files</summary> 📝 `src/cascadia/TerminalCore/Terminal.cpp` (+9 -141) 📝 `src/cascadia/TerminalCore/Terminal.hpp` (+2 -3) 📝 `src/cascadia/TerminalCore/TerminalApi.cpp` (+62 -22) 📝 `src/cascadia/UnitTests_TerminalCore/ConptyRoundtripTests.cpp` (+22 -19) 📝 `src/host/_stream.cpp` (+1 -189) 📝 `src/host/output.cpp` (+1 -2) 📝 `src/host/outputStream.cpp` (+19 -50) 📝 `src/host/outputStream.hpp` (+1 -3) 📝 `src/host/screenInfo.cpp` (+0 -60) 📝 `src/host/screenInfo.hpp` (+0 -8) 📝 `src/host/ut_host/ScreenBufferTests.cpp` (+31 -8) 📝 `src/terminal/adapter/ITerminalApi.hpp` (+1 -2) 📝 `src/terminal/adapter/adaptDispatch.cpp` (+129 -28) 📝 `src/terminal/adapter/adaptDispatch.hpp` (+5 -3) 📝 `src/terminal/adapter/ut_adapter/adapterTest.cpp` (+47 -100) </details> ### 📄 Description The main purpose of this PR was to merge the `ITerminalApi::LineFeed` implementations into a shared method in `AdaptDispatch`, and avoid the VT code path depending on the `AdjustCursorPosition` function (which could then be massively simplified). This refactoring also fixes some bugs that existed in the original `LineFeed` implementations. ## References and Relevant Issues This helps to close the gap between the Conhost and Terminal (#13408). This improves some of the scrollbar mark bugs mentioned in #11000. ## Detailed Description of the Pull Request / Additional comments I had initially hoped the line feed functionality could be implemented entirely within `AdaptDispatch`, but there is still some Conhost and Terminal-specific behavior that needs to be triggered when we reach the bottom of the buffer, and the row coordinates are cycled. In Conhost we need to trigger an accessibility scroll event, and in Windows Terminal we need to update selection and marker offsets, reset pattern intervals, and preserve the user's scroll offset. This is now handled by a new `NotifyBufferRotation` method in `ITerminalApi`. But this made me realise that the `_EraseAll` method should have been doing the same thing when it reached the bottom of the buffer. So I've added a call to the new `NotifyBufferRotation` API from there as well. And in the case of Windows Terminal, the scroll offset preservation was something that was also needed for a regular viewport pan. So I've put that in a separate `_PreserveUserScrollOffset` method which is called from the `SetViewportPosition` handler as well. ## Validation Steps Performed Because of the API changes, there were a number of unit tests that needed to be updated: - Some of the `ScreenBufferTests` were accessing margin state in the `SCREEN_INFORMATION` class which doesn't exist anymore, so I had to add a little helper function which now manually detects the active margins. - Some of the `AdapterTest` tests were dependent on APIs that no longer exist, so they needed to be rewritten so they now check the resulting state rather than expecting a mock API call. - The `ScrollWithMargins` test in `ConptyRoundtripTests` was testing functionality that didn't previously work correctly (issue #3673). Now that it's been fixed, that test needed to be updated accordingly. Other than getting the unit tests working, I've manually verified that issue #3673 is now fixed. And I've also checked that the scroll markers, selections, and user scroll offset are all being updated correctly, both with a regular viewport pan, as well as when overrunning the buffer. Closes #3673 --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
claunia added the pull-request label 2026-01-31 09:39:54 +00:00
Sign in to join this conversation.
No Label pull-request
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#30296