From b8d88fd8a208868df0769ddedd49d85079f8c57b Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Tue, 19 Mar 2024 11:50:31 -0700 Subject: [PATCH] terminal: deleteLines with zero count should do nothing --- src/terminal/Terminal.zig | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/terminal/Terminal.zig b/src/terminal/Terminal.zig index 40c475edc..77e76acc6 100644 --- a/src/terminal/Terminal.zig +++ b/src/terminal/Terminal.zig @@ -1353,6 +1353,9 @@ pub fn insertLines(self: *Terminal, count: usize) void { /// /// Moves the cursor to the left margin. pub fn deleteLines(self: *Terminal, count_req: usize) void { + // Rare, but happens + if (count_req == 0) return; + // If the cursor is outside the scroll region we do nothing. if (self.screen.cursor.y < self.scrolling_region.top or self.screen.cursor.y > self.scrolling_region.bottom or @@ -5719,6 +5722,16 @@ test "Terminal: deleteLines left/right scroll region high count" { } } +test "Terminal: deleteLines zero" { + const alloc = testing.allocator; + var t = try init(alloc, .{ .cols = 2, .rows = 5 }); + defer t.deinit(alloc); + + // This should do nothing + t.setCursorPos(1, 1); + t.deleteLines(0); +} + test "Terminal: default style is empty" { const alloc = testing.allocator; var t = try init(alloc, .{ .rows = 5, .cols = 5 });