Honor background color erase when scrolling - #104
Conversation
JohnCampionJr
left a comment
There was a problem hiding this comment.
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.
6e5bf59 to
f080652
Compare
There was a problem hiding this comment.
🟢 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 byInputHandler, 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.
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)