From 3cfce658c3738acd40e40fa4f9aacb9492f44c65 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Tue, 7 May 2024 09:52:03 -0700 Subject: [PATCH] terminal: dirty tracking in more places, tests coverage --- src/terminal/PageList.zig | 10 ++++++++++ src/terminal/Screen.zig | 15 +++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/src/terminal/PageList.zig b/src/terminal/PageList.zig index e1da55ad4..158717359 100644 --- a/src/terminal/PageList.zig +++ b/src/terminal/PageList.zig @@ -2023,6 +2023,12 @@ pub fn eraseRow( } } + { + // Set all the rows as dirty in this page + var dirty = page.data.dirtyBitSet(); + dirty.setRangeValue(.{ .start = pn.y, .end = page.data.size.rows }, true); + } + // We iterate through all of the following pages in order to move their // rows up by 1 as well. while (page.next) |next| { @@ -2054,6 +2060,10 @@ pub fn eraseRow( fastmem.rotateOnce(Row, rows[0..page.data.size.rows]); + // Set all the rows as dirty + var dirty = page.data.dirtyBitSet(); + dirty.setRangeValue(.{ .start = 0, .end = page.data.size.rows }, true); + // Our tracked pins for this page need to be updated. // If the pin is in row 0 that means the corresponding row has // been moved to the previous page. Otherwise, move it up by 1. diff --git a/src/terminal/Screen.zig b/src/terminal/Screen.zig index 3ab434048..45d5db71b 100644 --- a/src/terminal/Screen.zig +++ b/src/terminal/Screen.zig @@ -565,10 +565,17 @@ pub fn cursorDownScroll(self: *Screen) !void { self.cursor.page_row, self.cursor.page_pin.page.data.getCells(self.cursor.page_row), ); + + var dirty = self.cursor.page_pin.page.data.dirtyBitSet(); + dirty.set(0); } else { // eraseRow will shift everything below it up. try self.pages.eraseRow(.{ .active = .{} }); + // Note we don't need to mark anything dirty in this branch + // because eraseRow will mark all the rotated rows as dirty + // in the entire page. + // We need to move our cursor down one because eraseRows will // preserve our pin directly and we're erasing one row. const page_pin = self.cursor.page_pin.down(1).?; @@ -2909,6 +2916,11 @@ test "Screen: scrolling" { }, cell.content.color_rgb); } + // Everything is dirty because we have no scrollback + try testing.expect(s.pages.isDirty(.{ .active = .{ .x = 0, .y = 0 } })); + try testing.expect(s.pages.isDirty(.{ .active = .{ .x = 0, .y = 1 } })); + try testing.expect(s.pages.isDirty(.{ .active = .{ .x = 0, .y = 2 } })); + // Scrolling to the bottom does nothing s.scroll(.{ .active = {} }); @@ -2934,6 +2946,9 @@ test "Screen: scrolling with a single-row screen no scrollback" { defer alloc.free(contents); try testing.expectEqualStrings("", contents); } + + // Screen should be dirty + try testing.expect(s.pages.isDirty(.{ .active = .{ .x = 0, .y = 0 } })); } test "Screen: scrolling with a single-row screen with scrollback" {