From 044b09922743d587d6bec42fe3f66c1ca569e3d3 Mon Sep 17 00:00:00 2001 From: Tim Culverhouse Date: Mon, 10 Jun 2024 05:43:59 -0500 Subject: [PATCH] widgets(terminal): handle scrolling_region in CUU, CUD --- src/widgets/terminal/Screen.zig | 5 +---- src/widgets/terminal/Terminal.zig | 24 ++++++++++++++++++------ 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/src/widgets/terminal/Screen.zig b/src/widgets/terminal/Screen.zig index ef3ab87..c83f86e 100644 --- a/src/widgets/terminal/Screen.zig +++ b/src/widgets/terminal/Screen.zig @@ -318,10 +318,7 @@ pub fn cursorLeft(self: *Screen, n: usize) void { self.scrolling_region.left, ) else - self.cursor.col = @max( - self.cursor.col -| n, - 0, - ); + self.cursor.col = self.cursor.col -| n; } pub fn eraseRight(self: *Screen) void { diff --git a/src/widgets/terminal/Terminal.zig b/src/widgets/terminal/Terminal.zig index dc6d479..f84154e 100644 --- a/src/widgets/terminal/Terminal.zig +++ b/src/widgets/terminal/Terminal.zig @@ -255,18 +255,30 @@ fn run(self: *Terminal) !void { .ss3 => |ss3| std.log.err("unhandled ss3: {c}", .{ss3}), .csi => |seq| { switch (seq.final) { - 'A' => { + 'A', 'k' => { var iter = seq.iterator(u16); const delta = iter.next() orelse 1; - self.back_screen.cursor.row = self.back_screen.cursor.row -| delta; + if (self.back_screen.withinScrollingRegion()) + self.back_screen.cursor.row = @max( + self.back_screen.cursor.row -| delta, + self.back_screen.scrolling_region.top, + ) + else + self.back_screen.cursor.row = self.back_screen.cursor.row -| delta; }, 'B' => { // CUD var iter = seq.iterator(u16); const delta = iter.next() orelse 1; - self.back_screen.cursor.row = @min( - self.back_screen.height - 1, - self.back_screen.cursor.row + delta, - ); + if (self.back_screen.withinScrollingRegion()) + self.back_screen.cursor.row = @min( + self.back_screen.scrolling_region.bottom, + self.back_screen.cursor.row + delta, + ) + else + self.back_screen.cursor.row = @min( + self.back_screen.height - 1, + self.back_screen.cursor.row + delta, + ); }, 'C' => { self.back_screen.cursor.pending_wrap = false;