terminal: deleteLines with zero count should do nothing

This commit is contained in:
Mitchell Hashimoto
2024-03-19 11:50:31 -07:00
parent 56feeb28a8
commit b8d88fd8a2

View File

@ -1353,6 +1353,9 @@ pub fn insertLines(self: *Terminal, count: usize) void {
/// ///
/// Moves the cursor to the left margin. /// Moves the cursor to the left margin.
pub fn deleteLines(self: *Terminal, count_req: usize) void { 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 the cursor is outside the scroll region we do nothing.
if (self.screen.cursor.y < self.scrolling_region.top or if (self.screen.cursor.y < self.scrolling_region.top or
self.screen.cursor.y > self.scrolling_region.bottom 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" { test "Terminal: default style is empty" {
const alloc = testing.allocator; const alloc = testing.allocator;
var t = try init(alloc, .{ .rows = 5, .cols = 5 }); var t = try init(alloc, .{ .rows = 5, .cols = 5 });