Skip to content

fix: background-colour erase (bce) for ESC[K past written text - #235

Open
smohekey wants to merge 1 commit into
TerminalStudio:masterfrom
smohekey:fix/bce-background-color-erase
Open

fix: background-colour erase (bce) for ESC[K past written text#235
smohekey wants to merge 1 commit into
TerminalStudio:masterfrom
smohekey:fix/bce-background-color-erase

Conversation

@smohekey

Copy link
Copy Markdown

Problem

A BufferLine is only painted up to its _length, and eraseRange clamps the erase to _length. So when an application sets a background colour and then emits ESC[K (erase to end of line) to fill the rest of a row — the standard, efficient way to draw a full-width coloured row — only the cells under the already-written text get the background; the rest of the row stays the default colour.

This is background-colour erase (bce), which xterm, VTE, and xterm.js all implement. Full-screen TUIs that draw diffs or status bars this way (e.g. the Codex CLI) render patchy backgrounds in xterm.dart.

Reproduce

final terminal = Terminal()..resize(20, 5);
terminal.write('\x1b[42mAB\x1b[K'); // green bg, "AB", then erase-to-end-of-line
// before: cells past "AB" have the default background
// after:  cells past "AB" carry the green background

Fix

When the pen carries an explicit background, grow the line to the erase boundary so the erased cells exist and render with that background. Default-background erases stay trimmed, preserving the previous behaviour (and keeping trailing cells out of selection/copy).

Test

Adds test/src/core/buffer/bce_test.dart covering both the coloured-erase fill and the default-erase-stays-trimmed case.

A BufferLine is only painted up to its `_length`, and `eraseRange` clamped the
erase to `_length` — so an app that sets a background then emits `ESC[K` (erase
to end of line) to fill the rest of a row got a row coloured only under the text
it had written, not the full width. This is background-colour erase (bce), which
real terminals and xterm.js implement.

When the pen carries an explicit background, grow the line to the erase boundary
so the erased cells exist and render with that background. Default-background
erases stay trimmed, preserving the previous behaviour (and keeping trailing
cells out of selection/copy).

Reproduces with e.g. `ESC[42mAB ESC[K` — cells past "AB" now carry the green
background. Full-screen TUIs that draw diffs this way (e.g. the Codex CLI) were
rendering patchy backgrounds without it.
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.

1 participant