Skip to content

Expose lines leaving the terminal viewport - #158

Merged
tomlm merged 8 commits into
tomlm:mainfrom
simonefil:main
Oct 13, 2026
Merged

tomlm merged 8 commits into
tomlm:mainfrom
simonefil:main

Conversation

@simonefil

Copy link
Copy Markdown
Contributor

Motivation

Headless terminal hosts may need to persist or process rows as they leave the active viewport. One example is maintaining an external, bounded history that survives beyond
XTerm.NET's in-memory scrollback.

The existing Scrolled, Trimmed, and BufferChanged events do not provide the affected BufferLine before it is moved, removed, or recycled. A host therefore cannot reliably
capture the final contents and attributes of that row.

Changes

This adds a LineExitedViewport event to Terminal. The event reports:

  • the BufferLine leaving the viewport;
  • whether it belongs to the normal or alternate buffer;
  • whether it exited because of scrolling or buffer deactivation.

Scroll notifications are raised synchronously before the line can be spliced or recycled. Full-width scroll regions are supported; narrowed left/right margins do not raise the
event because they move only part of each row.

When switching buffers, the event is raised for meaningful visible rows before the previous buffer is deactivated. Trailing empty rows are omitted.

@tomlm
tomlm requested review from JohnCampionJr and a balanced review from Copilot September 27, 2026 02:54

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟡 Changes recommended

Downward scrolling, reset-driven deactivation, and metadata-only rows can currently lose lines without notification.

Review effort: Balanced
Findings: 3 Medium severity · 1 Low severity

Open (4)
What changed in this PR

Adds notifications for lines leaving the active terminal viewport.

Changes:

  • Introduces LineExitedViewport and exit-reason metadata.
  • Emits notifications during upward scrolling and buffer switches.
  • Adds coverage for scrolling, margins, and buffer switching.
File Description
Terminal.cs Exposes and raises viewport-exit events.
Events/​TerminalEvents.cs Defines event arguments.
Common/​Types.cs Defines line-exit reasons.
Buffer/​TerminalBuffer.cs Emits notifications during upward scrolling.
LineExitedViewportTests.cs Tests core event behavior.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread src/XTerm.NET/Buffer/TerminalBuffer.cs
Comment thread src/XTerm.NET/Terminal.cs Outdated
Comment thread src/XTerm.NET/Terminal.cs Outdated
Comment thread src/XTerm.NET/Terminal.cs
@JohnCampionJr

Copy link
Copy Markdown
Collaborator

@simonefil this is a good idea; can you address the code reviews from copilot please?

@simonefil

Copy link
Copy Markdown
Contributor Author

Thanks for the review! All four Copilot findings have now been addressed in 1ff4cec, i also added regression tests for these cases

@tomlm
tomlm merged commit 9f8f5ee into tomlm:main Oct 13, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants