From 9137f52cbfdefc70b64551089e8c1f9abe4d9f01 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Mon, 11 Mar 2024 20:13:45 -0700 Subject: [PATCH] terminal: resize cols without reflow handles higher caps --- src/terminal/PageList.zig | 11 +++++------ src/terminal/Terminal.zig | 20 ++++++++++++++++++++ 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/src/terminal/PageList.zig b/src/terminal/PageList.zig index e45f1d328..dcb540276 100644 --- a/src/terminal/PageList.zig +++ b/src/terminal/PageList.zig @@ -581,7 +581,7 @@ fn resizeCols( if (row.wrap) break :no_reflow; } - try self.resizeWithoutReflowGrowCols(cap, chunk); + try self.resizeWithoutReflowGrowCols(cols, chunk); continue; } @@ -1245,11 +1245,9 @@ fn resizeWithoutReflow(self: *PageList, opts: Resize) !void { // pages may not have the capacity for this. If they don't have // the capacity we need to allocate a new page and copy the data. .gt => { - const cap = try std_capacity.adjust(.{ .cols = cols }); - var it = self.pageIterator(.right_down, .{ .screen = .{} }, null); while (it.next()) |chunk| { - try self.resizeWithoutReflowGrowCols(cap, chunk); + try self.resizeWithoutReflowGrowCols(cols, chunk); } self.cols = cols; @@ -1260,11 +1258,12 @@ fn resizeWithoutReflow(self: *PageList, opts: Resize) !void { fn resizeWithoutReflowGrowCols( self: *PageList, - cap: Capacity, + cols: size.CellCountInt, chunk: PageIterator.Chunk, ) !void { - assert(cap.cols > self.cols); + assert(cols > self.cols); const page = &chunk.page.data; + const cap = try page.capacity.adjust(.{ .cols = cols }); // Update our col count const old_cols = self.cols; diff --git a/src/terminal/Terminal.zig b/src/terminal/Terminal.zig index dae0fbe92..75646fc88 100644 --- a/src/terminal/Terminal.zig +++ b/src/terminal/Terminal.zig @@ -7708,6 +7708,26 @@ test "Terminal: resize with wraparound on" { try testing.expectEqualStrings("01\n23", str); } +test "Terminal: resize with high unique style per cell" { + const alloc = testing.allocator; + var t = try init(alloc, 30, 30); + defer t.deinit(alloc); + + for (0..t.rows) |y| { + for (0..t.cols) |x| { + t.setCursorPos(y, x); + try t.setAttribute(.{ .direct_color_bg = .{ + .r = @intCast(x), + .g = @intCast(y), + .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);