terminal: resize handles increased styles/graphemes

This commit is contained in:
Mitchell Hashimoto
2024-03-11 20:42:26 -07:00
parent 9137f52cbf
commit 03abde6ba8
2 changed files with 27 additions and 5 deletions

View File

@ -537,9 +537,6 @@ fn resizeCols(
) !void {
assert(cols != self.cols);
// Our new capacity, ensure we can fit the cols
const cap = try std_capacity.adjust(.{ .cols = cols });
// If we have a cursor position (x,y), then we try under any col resizing
// to keep the same number remaining active rows beneath it. This is a
// very special case if you can imagine clearing the screen (i.e.
@ -588,7 +585,7 @@ fn resizeCols(
// Note: we can do a fast-path here if all of our rows in this
// page already fit within the new capacity. In that case we can
// do a non-reflow resize.
try self.reflowPage(cap, chunk.page);
try self.reflowPage(cols, chunk.page);
}
// If our total rows is less than our active rows, we need to grow.
@ -774,7 +771,7 @@ const ReflowCursor = struct {
/// function.
fn reflowPage(
self: *PageList,
cap: Capacity,
cols: size.CellCountInt,
initial_node: *List.Node,
) !void {
// The cursor tracks where we are in the source page.
@ -810,6 +807,10 @@ fn reflowPage(
// Our new capacity when growing columns may also shrink rows. So we
// need to do a loop in order to potentially make multiple pages.
dst_loop: while (true) {
// Our cap is based on the source page cap so we can inherit
// potentially increased styles/graphemes/etc.
const cap = try src_cursor.page.capacity.adjust(.{ .cols = cols });
// Create our new page and our cursor restarts at 0,0 in the new page.
// The new page always starts with a size of 1 because we know we have
// at least one row to copy from the src.

View File

@ -7728,6 +7728,27 @@ test "Terminal: resize with high unique style per cell" {
try t.resize(alloc, 60, 30);
}
test "Terminal: resize with high unique style per cell with wrapping" {
const alloc = testing.allocator;
var t = try init(alloc, 30, 30);
defer t.deinit(alloc);
const cell_count: u16 = @intCast(t.rows * t.cols);
for (0..cell_count) |i| {
const r: u8 = @intCast(i >> 8);
const g: u8 = @intCast(i & 0xFF);
try t.setAttribute(.{ .direct_color_bg = .{
.r = r,
.g = g,
.b = 0,
} });
try t.print('x');
}
try t.resize(alloc, 60, 30);
}
test "Terminal: DECCOLM without DEC mode 40" {
const alloc = testing.allocator;
var t = try init(alloc, 5, 5);