terminal: CUB with reverse wrap on first row should not crash

This commit is contained in:
Mitchell Hashimoto
2023-10-26 23:01:55 -07:00
parent ea1ef0641d
commit 578dd730f9

View File

@ -1464,12 +1464,6 @@ pub fn cursorLeft(self: *Terminal, count_req: usize) void {
continue; continue;
} }
// If our previous line is not wrapped then we are done.
if (wrap_mode != .reverse_extended) {
const row = self.screen.getRow(.{ .active = self.screen.cursor.y - 1 });
if (!row.isWrapped()) break;
}
// UNDEFINED TERMINAL BEHAVIOR. This situation is not handled in xterm // UNDEFINED TERMINAL BEHAVIOR. This situation is not handled in xterm
// and currently results in a crash in xterm. Given no other known // and currently results in a crash in xterm. Given no other known
// terminal [to me] implements XTREVWRAP2, I decided to just mimick // terminal [to me] implements XTREVWRAP2, I decided to just mimick
@ -1482,6 +1476,12 @@ pub fn cursorLeft(self: *Terminal, count_req: usize) void {
break; break;
} }
// If our previous line is not wrapped then we are done.
if (wrap_mode != .reverse_extended) {
const row = self.screen.getRow(.{ .active = self.screen.cursor.y - 1 });
if (!row.isWrapped()) break;
}
self.screen.cursor.y -= 1; self.screen.cursor.y -= 1;
self.screen.cursor.x = right_margin; self.screen.cursor.x = right_margin;
count -= 1; count -= 1;
@ -6154,6 +6154,22 @@ test "Terminal: cursorLeft extended reverse wrap above top scroll region" {
try testing.expectEqual(@as(usize, 0), t.screen.cursor.y); try testing.expectEqual(@as(usize, 0), t.screen.cursor.y);
} }
test "Terminal: cursorLeft reverse wrap on first row" {
const alloc = testing.allocator;
var t = try init(alloc, 5, 5);
defer t.deinit(alloc);
t.modes.set(.wraparound, true);
t.modes.set(.reverse_wrap, true);
t.setTopAndBottomMargin(3, 0);
t.setCursorPos(1, 2);
t.cursorLeft(1000);
try testing.expectEqual(@as(usize, 0), t.screen.cursor.x);
try testing.expectEqual(@as(usize, 0), t.screen.cursor.y);
}
test "Terminal: cursorDown basic" { test "Terminal: cursorDown basic" {
const alloc = testing.allocator; const alloc = testing.allocator;
var t = try init(alloc, 5, 5); var t = try init(alloc, 5, 5);