terminal: insertLines with count 0 no longer crashes

This commit is contained in:
Mitchell Hashimoto
2022-12-14 21:29:06 -08:00
parent 0592e4fa1a
commit 8534e5a186

View File

@ -1226,6 +1226,9 @@ pub fn insertLines(self: *Terminal, count: usize) !void {
const tracy = trace(@src());
defer tracy.end();
// Rare, but happens
if (count == 0) return;
// Move the cursor to the left margin
self.screen.cursor.x = 0;
@ -1790,6 +1793,16 @@ test "Terminal: insertLines" {
}
}
test "Terminal: insertLines zero" {
const alloc = testing.allocator;
var t = try init(alloc, 2, 5);
defer t.deinit(alloc);
// This should do nothing
t.setCursorPos(1, 1);
try t.insertLines(0);
}
test "Terminal: insertLines with scroll region" {
const alloc = testing.allocator;
var t = try init(alloc, 2, 6);