From baa3903d22bec45cb159245c6f4e9f6c3fc87e4b Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Thu, 29 Feb 2024 22:28:14 -0800 Subject: [PATCH] terminal/new: screen resize no reflow less rows --- src/terminal/new/PageList.zig | 1 + src/terminal/new/Screen.zig | 39 +++++++++++++++++------------------ 2 files changed, 20 insertions(+), 20 deletions(-) diff --git a/src/terminal/new/PageList.zig b/src/terminal/new/PageList.zig index 6644393f1..8a07949d7 100644 --- a/src/terminal/new/PageList.zig +++ b/src/terminal/new/PageList.zig @@ -363,6 +363,7 @@ pub const Resize = struct { /// TODO: docs pub fn resize(self: *PageList, opts: Resize) !void { if (!opts.reflow) return try self.resizeWithoutReflow(opts); + @panic("TODO: resize with text reflow"); } fn resizeWithoutReflow(self: *PageList, opts: Resize) !void { diff --git a/src/terminal/new/Screen.zig b/src/terminal/new/Screen.zig index 69f1d53d6..34e0380b2 100644 --- a/src/terminal/new/Screen.zig +++ b/src/terminal/new/Screen.zig @@ -584,7 +584,7 @@ pub fn resize( // If we have the same number of columns, text can't possibly // reflow in any way, so we do the quicker thing and do a resize // without reflow checks. - try self.resizeWithoutReflow(rows, cols); + try self.resizeWithoutReflow(cols, rows); return; } @@ -596,11 +596,10 @@ pub fn resize( /// with zeros. pub fn resizeWithoutReflow( self: *Screen, - rows: size.CellCountInt, cols: size.CellCountInt, + rows: size.CellCountInt, ) !void { - // If we're resizing to the same size, do nothing. - if (self.pages.cols == cols and self.pages.rows == rows) return; + try self.pages.resize(.{ .rows = rows, .cols = cols, .reflow = false }); } /// Set a style attribute for the current cursor. @@ -1822,19 +1821,19 @@ test "Screen: resize (no reflow) more rows" { } } -// test "Screen: resize (no reflow) less rows" { -// const testing = std.testing; -// const alloc = testing.allocator; -// -// var s = try init(alloc, 10, 3, 0); -// defer s.deinit(); -// const str = "1ABCD\n2EFGH\n3IJKL"; -// try s.testWriteString(str); -// try s.resizeWithoutReflow(10, 2); -// -// { -// const contents = try s.dumpStringAlloc(alloc, .{ .viewport = .{} }); -// defer alloc.free(contents); -// try testing.expectEqualStrings("2EFGH\n3IJKL", contents); -// } -// } +test "Screen: resize (no reflow) less rows" { + const testing = std.testing; + const alloc = testing.allocator; + + var s = try init(alloc, 10, 3, 0); + defer s.deinit(); + const str = "1ABCD\n2EFGH\n3IJKL"; + try s.testWriteString(str); + try s.resizeWithoutReflow(10, 2); + + { + const contents = try s.dumpStringAlloc(alloc, .{ .viewport = .{} }); + defer alloc.free(contents); + try testing.expectEqualStrings("2EFGH\n3IJKL", contents); + } +}