From bd1a7d3db14a30a0ccdb312212efbb328d2c352b Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Tue, 16 Apr 2024 11:03:39 -0700 Subject: [PATCH] terminal: scrollDown dirty tests --- src/terminal/Terminal.zig | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/src/terminal/Terminal.zig b/src/terminal/Terminal.zig index 647a3638a..569ed502f 100644 --- a/src/terminal/Terminal.zig +++ b/src/terminal/Terminal.zig @@ -1594,6 +1594,10 @@ pub fn deleteLines(self: *Terminal, count_req: usize) void { const src: *Row = src_rac.row; const dst: *Row = dst_rac.row; + // Mark both our src/dst as dirty + p.markDirty(); + src_p.markDirty(); + self.rowWillBeShifted(&src_p.page.data, src); self.rowWillBeShifted(&p.page.data, dst); @@ -1659,6 +1663,9 @@ pub fn deleteLines(self: *Terminal, count_req: usize) void { while (it.next()) |p| { const row: *Row = p.rowAndCell().row; + // This row is now dirty + p.markDirty(); + // Clear the src row. const page = &p.page.data; const cells = page.getCells(row); @@ -4818,11 +4825,17 @@ test "Terminal: scrollUp simple" { try t.linefeed(); try t.printString("GHI"); t.setCursorPos(2, 2); + const cursor = t.screen.cursor; + t.clearDirty(); t.scrollUp(1); try testing.expectEqual(cursor.x, t.screen.cursor.x); try testing.expectEqual(cursor.y, t.screen.cursor.y); + try testing.expect(t.isDirty(.{ .active = .{ .x = 0, .y = 0 } })); + try testing.expect(t.isDirty(.{ .active = .{ .x = 0, .y = 1 } })); + try testing.expect(t.isDirty(.{ .active = .{ .x = 0, .y = 2 } })); + { const str = try t.plainString(testing.allocator); defer testing.allocator.free(str); @@ -4844,8 +4857,14 @@ test "Terminal: scrollUp top/bottom scroll region" { try t.printString("GHI"); t.setTopAndBottomMargin(2, 3); t.setCursorPos(1, 1); + + t.clearDirty(); t.scrollUp(1); + try testing.expect(!t.isDirty(.{ .active = .{ .x = 0, .y = 0 } })); + try testing.expect(t.isDirty(.{ .active = .{ .x = 0, .y = 1 } })); + try testing.expect(t.isDirty(.{ .active = .{ .x = 0, .y = 2 } })); + { const str = try t.plainString(testing.allocator); defer testing.allocator.free(str); @@ -4868,11 +4887,17 @@ test "Terminal: scrollUp left/right scroll region" { t.scrolling_region.left = 1; t.scrolling_region.right = 3; t.setCursorPos(2, 2); + const cursor = t.screen.cursor; + t.clearDirty(); t.scrollUp(1); try testing.expectEqual(cursor.x, t.screen.cursor.x); try testing.expectEqual(cursor.y, t.screen.cursor.y); + try testing.expect(t.isDirty(.{ .active = .{ .x = 0, .y = 0 } })); + try testing.expect(t.isDirty(.{ .active = .{ .x = 0, .y = 1 } })); + try testing.expect(t.isDirty(.{ .active = .{ .x = 0, .y = 2 } })); + { const str = try t.plainString(testing.allocator); defer testing.allocator.free(str); @@ -4910,8 +4935,13 @@ test "Terminal: scrollUp full top/bottom region" { t.setCursorPos(5, 1); try t.printString("ABCDE"); t.setTopAndBottomMargin(2, 5); + + t.clearDirty(); t.scrollUp(4); + try testing.expect(!t.isDirty(.{ .active = .{ .x = 0, .y = 0 } })); + try testing.expect(t.isDirty(.{ .active = .{ .x = 0, .y = 1 } })); + { const str = try t.plainString(testing.allocator); defer testing.allocator.free(str); @@ -4930,8 +4960,13 @@ test "Terminal: scrollUp full top/bottomleft/right scroll region" { t.modes.set(.enable_left_and_right_margin, true); t.setTopAndBottomMargin(2, 5); t.setLeftAndRightMargin(2, 4); + + t.clearDirty(); t.scrollUp(4); + try testing.expect(!t.isDirty(.{ .active = .{ .x = 0, .y = 0 } })); + for (1..5) |y| try testing.expect(t.isDirty(.{ .active = .{ .x = 0, .y = y } })); + { const str = try t.plainString(testing.allocator); defer testing.allocator.free(str);