Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions lib/src/core/buffer/line.dart
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,22 @@ class BufferLine with IndexedItem {
eraseCell(end - 1, style);
}

// Background-colour erase (bce): a line is only painted up to `_length`, so clamping the erase to
// `_length` would silently drop cells an app expects filled with the current background — e.g. codex
// sets a diff row's background then emits `ESC[K` to colour the rest of the row, leaving the row
// patchy instead of full-width. When the pen carries an explicit background, grow the line to the
// erase boundary so those cells exist and render. (Default-background erases stay trimmed, preserving
// the previous behaviour and keeping trailing cells out of selection/copy.)
if (style.background != 0 && end > _length) {
final gapStart = _length;
resize(end);
// A cursor parked past the written text leaves a gap before `start`; keep it default rather than
// whatever stale data the grown buffer held.
for (var i = gapStart; i < start && i < end; i++) {
resetCell(i);
}
}

end = min(end, _length);
for (var i = start; i < end; i++) {
eraseCell(i, style);
Expand Down
33 changes: 33 additions & 0 deletions test/src/core/buffer/bce_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import 'package:test/test.dart';
import 'package:xterm/core.dart';

void main() {
group('background-colour erase (bce)', () {
test('ESC[K after short text fills the rest of the row with the current background', () {
final terminal = Terminal();
terminal.resize(20, 5);

// Green background, two characters, then erase-to-end-of-line.
terminal.write('\x1b[42mAB\x1b[K');

final line = terminal.buffer.lines[0];
final green = line.getBackground(0); // the background used for the written cells
expect(green, isNot(0), reason: 'sanity: an explicit background is set');

// Cells past the written text must carry the same background (bce), not the default.
expect(line.getBackground(2), green);
expect(line.getBackground(10), green);
expect(line.getBackground(19), green);
});

test('ESC[K with the default background does not extend the line', () {
final terminal = Terminal();
terminal.resize(20, 5);

terminal.write('AB\x1b[K');

// No explicit background → erased cells stay at the default (0); the line is not grown.
expect(terminal.buffer.lines[0].getBackground(10), 0);
});
});
}