From d71657ded1c4fcafac0554e2505a1e66ffb5f1c3 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Sat, 2 Mar 2024 10:03:28 -0800 Subject: [PATCH] terminal/new: start porting resize tests, bugs --- src/terminal/Screen.zig | 3 + src/terminal/new/Screen.zig | 118 ++++++++++++++++++++++++++++++++---- 2 files changed, 110 insertions(+), 11 deletions(-) diff --git a/src/terminal/Screen.zig b/src/terminal/Screen.zig index 20c9dae00..814e42080 100644 --- a/src/terminal/Screen.zig +++ b/src/terminal/Screen.zig @@ -6353,6 +6353,7 @@ test "Screen: resize (no reflow) more rows with soft wrapping" { } } +// X test "Screen: resize more rows no scrollback" { const testing = std.testing; const alloc = testing.allocator; @@ -6379,6 +6380,7 @@ test "Screen: resize more rows no scrollback" { } } +// X test "Screen: resize more rows with empty scrollback" { const testing = std.testing; const alloc = testing.allocator; @@ -6405,6 +6407,7 @@ test "Screen: resize more rows with empty scrollback" { } } +// X test "Screen: resize more rows with populated scrollback" { const testing = std.testing; const alloc = testing.allocator; diff --git a/src/terminal/new/Screen.zig b/src/terminal/new/Screen.zig index 8a54cdf93..c894fdebd 100644 --- a/src/terminal/new/Screen.zig +++ b/src/terminal/new/Screen.zig @@ -599,18 +599,14 @@ pub fn resize( // No matter what we mark our image state as dirty self.kitty_images.dirty = true; - // We grow rows after cols so that we can do our unwrapping/reflow - // before we do a no-reflow grow. - // - // If our rows got smaller, we trim the scrollback. We do this after - // handling cols growing so that we can save as many lines as we can. - // We do it before cols shrinking so we can save compute on that operation. - if (rows != self.pages.rows) { - try self.resizeWithoutReflow(rows, self.cols); - assert(self.pages.rows == rows); - } + // Resize our pages + try self.pages.resize(.{ + .rows = rows, + .cols = cols, + .reflow = true, + }); - @panic("TODO"); + // TODO: cursor } /// Resize the screen without any reflow. In this mode, columns/rows will @@ -2060,6 +2056,106 @@ test "Screen: resize (no reflow) more rows with soft wrapping" { } } +test "Screen: resize more rows no scrollback" { + const testing = std.testing; + const alloc = testing.allocator; + + var s = try init(alloc, 5, 3, 0); + defer s.deinit(); + const str = "1ABCD\n2EFGH\n3IJKL"; + try s.testWriteString(str); + const cursor = s.cursor; + try s.resize(5, 10); + + // Cursor should not move + try testing.expectEqual(cursor.x, s.cursor.x); + try testing.expectEqual(cursor.y, s.cursor.y); + + { + const contents = try s.dumpStringAlloc(alloc, .{ .viewport = .{} }); + defer alloc.free(contents); + try testing.expectEqualStrings(str, contents); + } + { + const contents = try s.dumpStringAlloc(alloc, .{ .screen = .{} }); + defer alloc.free(contents); + try testing.expectEqualStrings(str, contents); + } +} + +test "Screen: resize more rows with empty scrollback" { + const testing = std.testing; + const alloc = testing.allocator; + + var s = try init(alloc, 5, 3, 10); + defer s.deinit(); + const str = "1ABCD\n2EFGH\n3IJKL"; + try s.testWriteString(str); + const cursor = s.cursor; + try s.resize(5, 10); + + // Cursor should not move + try testing.expectEqual(cursor.x, s.cursor.x); + try testing.expectEqual(cursor.y, s.cursor.y); + + { + const contents = try s.dumpStringAlloc(alloc, .{ .viewport = .{} }); + defer alloc.free(contents); + try testing.expectEqualStrings(str, contents); + } + { + const contents = try s.dumpStringAlloc(alloc, .{ .screen = .{} }); + defer alloc.free(contents); + try testing.expectEqualStrings(str, contents); + } +} + +test "Screen: resize more rows with populated scrollback" { + const testing = std.testing; + const alloc = testing.allocator; + + var s = try init(alloc, 5, 3, 5); + defer s.deinit(); + const str = "1ABCD\n2EFGH\n3IJKL\n4ABCD\n5EFGH"; + try s.testWriteString(str); + { + const contents = try s.dumpStringAlloc(alloc, .{ .viewport = .{} }); + defer alloc.free(contents); + const expected = "3IJKL\n4ABCD\n5EFGH"; + try testing.expectEqualStrings(expected, contents); + } + + // Set our cursor to be on the "4" + s.cursorAbsolute(0, 1); + { + const list_cell = s.pages.getCell(.{ .active = .{ + .x = s.cursor.x, + .y = s.cursor.y, + } }).?; + try testing.expectEqual(@as(u21, '4'), list_cell.cell.content.codepoint); + } + + // Resize + try s.resize(5, 10); + + // Cursor should still be on the "4" + // TODO + // { + // const list_cell = s.pages.getCell(.{ .active = .{ + // .x = s.cursor.x, + // .y = s.cursor.y, + // } }).?; + // try testing.expectEqual(@as(u21, '4'), list_cell.cell.content.codepoint); + // } + + // { + // const contents = try s.dumpStringAlloc(alloc, .{ .viewport = .{} }); + // defer alloc.free(contents); + // const expected = "3IJKL\n4ABCD\n5EFGH"; + // try testing.expectEqualStrings(expected, contents); + // } +} + // test "Screen: resize more cols no reflow" { // const testing = std.testing; // const alloc = testing.allocator;