From d81bb19af6267bf2f3b4817b7c52e3181558f464 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Sun, 24 Jul 2022 16:33:57 -0700 Subject: [PATCH] fix crash we can get with horizontal tabs off the end of the screen --- src/terminal/Terminal.zig | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/terminal/Terminal.zig b/src/terminal/Terminal.zig index 4ce1511fd..95f9452c8 100644 --- a/src/terminal/Terminal.zig +++ b/src/terminal/Terminal.zig @@ -665,7 +665,7 @@ pub fn horizontalTab(self: *Terminal) !void { const tracy = trace(@src()); defer tracy.end(); - while (self.screen.cursor.x < self.cols) { + while (self.screen.cursor.x < self.cols - 1) { // Move the cursor right self.screen.cursor.x += 1; @@ -1055,7 +1055,7 @@ test "Terminal: backspace" { test "Terminal: horizontal tabs" { const alloc = testing.allocator; - var t = try init(alloc, 80, 5); + var t = try init(alloc, 20, 5); defer t.deinit(alloc); // HT @@ -1066,6 +1066,12 @@ test "Terminal: horizontal tabs" { // HT try t.horizontalTab(); try testing.expectEqual(@as(usize, 15), t.screen.cursor.x); + + // HT at the end + try t.horizontalTab(); + try testing.expectEqual(@as(usize, 19), t.screen.cursor.x); + try t.horizontalTab(); + try testing.expectEqual(@as(usize, 19), t.screen.cursor.x); } test "Terminal: setCursorPosition" {