Skip to content

Honor background color erase when scrolling - #104

Merged
JohnCampionJr merged 3 commits into
tomlm:mainfrom
JohnCampionJr:codex/issue-96-bce-blank-lines
Aug 29, 2026
Merged

JohnCampionJr merged 3 commits into
tomlm:mainfrom
JohnCampionJr:codex/issue-96-bce-blank-lines

Conversation

@JohnCampionJr

Copy link
Copy Markdown
Collaborator

Fixes #96

Makes terminal buffers pull the active erase attributes when scrolling exposes blank cells. Only the current background is retained; foreground and rendition flags remain at their defaults.

Covers full-width upward scrolling, reverse scrolling, recycled scrollback rows, narrowed left/right margins, and alternate-screen switching.

Tests: dotnet test src/XTerm.NET.Tests/XTerm.NET.Tests.csproj --no-restore (1913 passed)

@JohnCampionJr JohnCampionJr left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Reviewed against a clean worktree; built and ran the suite (1913 passed).

The mechanism is right. Flags live in Extended, not Bg, so copying Bg alone yields bg-only and matches xterm.js _eraseAttrData(). Buffer switching is safe -- every path goes through SetBuffer.

Hot path: touched, but free. ScrollUp is reached from the print wrap-at-bottom, LF and CSI S, and now costs one null check plus a non-inlinable call returning a 12-byte struct per scrolled line -- against ResetInPlace's Array.Fill of ~4.8 KB at 240 columns. Three things I specifically checked and can confirm are unaffected: Array.Fill has no default-attribute fast path, so recycling costs the same; the print fast path gates on InsertMode/charset/HasMultiRowSizedRuns, never on attributes; and GetTrimmedLength/HasContent look at content only, so BCE-painted blanks do not start counting as content and do not perturb reflow, trimming or selection.

The concern is scope, not correctness: this gives the terminal two different BCE rules. Details inline.

Comment thread src/XTerm.NET/InputHandler.cs
Comment thread src/XTerm.NET/InputHandler.cs
Comment thread src/XTerm.NET/Buffer/TerminalBuffer.cs
@JohnCampionJr
JohnCampionJr requested a lite review from Copilot August 29, 2026 18:30
@JohnCampionJr
JohnCampionJr force-pushed the codex/issue-96-bce-blank-lines branch from 6e5bf59 to f080652 Compare August 29, 2026 18:31

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.

🟢 Approval recommended

The change cleanly implements BCE background-only erasure via a pull-based provider, updates the relevant scroll fill paths, and includes targeted regression tests for the stated scenarios.

Pull request overview

This PR implements BCE (background color erase) correctness for scrolled-in blank cells by having TerminalBuffer pull the current erase background from InputHandler when it needs to materialize new/recycled blank lines, including margin-box scrolling and alt-buffer scenarios.

Changes:

  • Added an erase-attributes provider hook on TerminalBuffer, supplied by InputHandler, to fetch the current background-only erase attributes on demand.
  • Updated scroll paths (full-width scroll up/down, recycled scrollback reuse, and margin-box scrolling fill) to use the provider instead of AttributeData.Default.
  • Added a dedicated test suite covering forward/reverse scrolling, recycled scrollback reuse, narrowed margins, and alternate-buffer switching.
File summaries
File Description
src/XTerm.NET/InputHandler.cs Supplies TerminalBuffer with a background-only erase attribute provider and reattaches it on buffer switches.
src/XTerm.NET/Buffer/TerminalBuffer.cs Uses pulled erase attributes when creating/resetting blank cells during scroll operations (including margin-box scroll).
src/XTerm.NET.Tests/BackgroundColorEraseScrollTests.cs Adds regression tests validating BCE background behavior across scroll paths and buffer switching.
Review details
  • Files reviewed: 4/4 changed files
  • Comments generated: 0
  • Review effort level: Lite

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

@JohnCampionJr
JohnCampionJr merged commit 5f68ce6 into tomlm:main Aug 29, 2026
2 checks passed
@JohnCampionJr
JohnCampionJr deleted the codex/issue-96-bce-blank-lines branch August 31, 2026 18:47
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.

Scrolled-in blank lines ignore BCE (background colour erase)

2 participants