From bfa574fa60f8a3a3c42d41af78a3181179aa3c84 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Wed, 28 Feb 2024 09:10:56 -0800 Subject: [PATCH] terminal/new: Screen new scrolldown should inherit bg color --- src/terminal/Screen.zig | 1 + src/terminal/new/Screen.zig | 49 +++++++++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+) diff --git a/src/terminal/Screen.zig b/src/terminal/Screen.zig index dcef37328..53471ac4a 100644 --- a/src/terminal/Screen.zig +++ b/src/terminal/Screen.zig @@ -3801,6 +3801,7 @@ test "Screen: getLine soft wrap" { try testing.expect(s.getLine(.{ .x = 7, .y = 1 }) == null); } +// X test "Screen: scrolling" { const testing = std.testing; const alloc = testing.allocator; diff --git a/src/terminal/new/Screen.zig b/src/terminal/new/Screen.zig index a97e5b348..8eb202189 100644 --- a/src/terminal/new/Screen.zig +++ b/src/terminal/new/Screen.zig @@ -314,6 +314,16 @@ pub fn cursorDownScroll(self: *Screen) !void { self.cursor.page_offset = page_offset; self.cursor.page_row = page_rac.row; self.cursor.page_cell = page_rac.cell; + + // Clear the new row so it gets our bg color. We only do this + // if we have a bg color at all. + if (self.cursor.style.bg_color != .none) { + self.clearCells( + &page_offset.page.data, + self.cursor.page_row, + page_offset.page.data.getCells(self.cursor.page_row), + ); + } } // The newly created line needs to be styled according to the bg color @@ -1064,3 +1074,42 @@ test "Screen eraseRows history with more lines" { try testing.expectEqualStrings("2\n3\n4\n5\n6", str); } } + +test "Screen: scrolling" { + const testing = std.testing; + const alloc = testing.allocator; + + var s = try init(alloc, 10, 3, 0); + defer s.deinit(); + try s.setAttribute(.{ .direct_color_bg = .{ .r = 155 } }); + try s.testWriteString("1ABCD\n2EFGH\n3IJKL"); + + // Scroll down, should still be bottom + try s.cursorDownScroll(); + { + // Test our contents rotated + const contents = try s.dumpStringAlloc(alloc, .{ .viewport = .{} }); + defer alloc.free(contents); + try testing.expectEqualStrings("2EFGH\n3IJKL", contents); + } + { + const list_cell = s.pages.getCell(.{ .active = .{ .x = 0, .y = 2 } }).?; + const cell = list_cell.cell; + try testing.expect(cell.content_tag == .bg_color_rgb); + try testing.expectEqual(Cell.RGB{ + .r = 155, + .g = 0, + .b = 0, + }, cell.content.color_rgb); + } + + // Scrolling to the bottom does nothing + s.scroll(.{ .active = {} }); + + { + // Test our contents rotated + const contents = try s.dumpStringAlloc(alloc, .{ .viewport = .{} }); + defer alloc.free(contents); + try testing.expectEqualStrings("2EFGH\n3IJKL", contents); + } +}