Skip to content

A modern terminal with a built-in multiplexer: close it and your sessions keep running. Run shells and tons of AI agents across your machines, then pick them up from desktop, browser, TUI and more. Written in Rust with no UI framework: interface drawn straight on the GPU. No Electron, GPUI or webview.

perf(surface): truncate and fill when a blank erase reaches the row end

RoversXe6ddda86a244
diff --git a/wezterm-surface/src/line/line.rs b/wezterm-surface/src/line/line.rs
index 276e49d4..da1deff4 100644
--- a/wezterm-surface/src/line/line.rs
+++ b/wezterm-surface/src/line/line.rs
@@ -1147,6 +1147,12 @@ impl Line {
cells.truncate(last + 1);
return;
}
+ // The whole row ends up blank. Vec storage historically
+ // retains the length of all-blank lines, so write the tail
+ // in one go; the trailing-blank scan could prune nothing.
+ cells.truncate(start + 1);
+ cells.resize(cols.end, cell.clone());
+ return;
}
// Vec storage historically retains the length of all-blank lines.
// Preserve that behavior, including styled wide-cell padding.
diff --git a/wezterm-surface/src/line/test.rs b/wezterm-surface/src/line/test.rs
index 595b42ce..fdb50ed1 100644
--- a/wezterm-surface/src/line/test.rs
+++ b/wezterm-surface/src/line/test.rs
@@ -1070,3 +1070,30 @@ fn ascii_overwrite_preserves_image_placements() {
check_ascii_against_scalar(&base, start, "0123456789", &CellAttributes::default());
}
}
+
+#[test]
+fn blank_fill_to_the_end_matches_scalar_writes_then_prune() {
+ // fill_range's Vec fast path: a blank fill from inside the row to at
+ // least its end. Its result must equal per-column writes plus pruning.
+ let mut styled = CellAttributes::default();
+ styled.set_background(wezterm_cell::color::ColorAttribute::PaletteIndex(4));
+ for text in ["hello world", "界🙂x", " ", "ab cd "] {
+ for attrs in [CellAttributes::default(), styled.clone()] {
+ let mut base = Line::from_text(text, &attrs, 1, None);
+ base.cells_mut();
+ let len = base.len();
+ for start in 0..len {
+ for end in [len, len + 1, 20] {
+ let mut actual = base.clone();
+ actual.fill_range(start..end, &Cell::blank(), 7);
+ let mut expected = base.clone();
+ for x in start..end {
+ expected.set_cell(x, Cell::blank(), 7);
+ }
+ expected.prune_trailing_blanks(7);
+ assert_eq!(actual, expected, "text={text:?} {start}..{end}");
+ }
+ }
+ }
+ }
+}