From dba027d307834f4d8b0f3480815b7471ef85ca4f Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Thu, 1 Sep 2022 01:09:06 -0700 Subject: [PATCH] resize should maintain minimum of screen rows --- src/terminal/Screen.zig | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/terminal/Screen.zig b/src/terminal/Screen.zig index 12dcca646..5f101fab1 100644 --- a/src/terminal/Screen.zig +++ b/src/terminal/Screen.zig @@ -775,7 +775,7 @@ pub fn resizeWithoutReflow(self: *Screen, rows: usize, cols: usize) !void { // Calculate our buffer size. This is going to be either the old data // with scrollback or the max capacity of our new size. We prefer the old // length so we can save all the data (ignoring col truncation). - const old_len = old.rowsWritten() * (cols + 1); + const old_len = @maximum(old.rowsWritten(), rows) * (cols + 1); const new_max_capacity = self.maxCapacity(); const buf_size = @minimum(old_len, new_max_capacity); @@ -1505,6 +1505,23 @@ test "Screen: resize (no reflow) less rows with scrollback" { } } +test "Screen: resize (no reflow) empty screen" { + const testing = std.testing; + const alloc = testing.allocator; + + var s = try init(alloc, 5, 5, 0); + defer s.deinit(); + try testing.expect(s.rowsWritten() == 0); + try testing.expectEqual(@as(usize, 5), s.rowsCapacity()); + + try s.resizeWithoutReflow(10, 10); + try testing.expect(s.rowsWritten() == 0); + + // This is the primary test for this test, we want to ensure we + // always have at least enough capacity for our rows. + try testing.expectEqual(@as(usize, 10), s.rowsCapacity()); +} + test "Screen: resize more rows no scrollback" { const testing = std.testing; const alloc = testing.allocator;