From aa9e492b26c470744b8e721be84a0316d9cb69e3 Mon Sep 17 00:00:00 2001 From: Tim Culverhouse Date: Sun, 9 Jun 2024 20:57:49 -0500 Subject: [PATCH] widgets(terminal): simplify cursorLeft logic --- src/widgets/terminal/Screen.zig | 14 ++++++++++---- src/widgets/terminal/Terminal.zig | 14 ++------------ 2 files changed, 12 insertions(+), 16 deletions(-) diff --git a/src/widgets/terminal/Screen.zig b/src/widgets/terminal/Screen.zig index b532a38..ef3ab87 100644 --- a/src/widgets/terminal/Screen.zig +++ b/src/widgets/terminal/Screen.zig @@ -311,11 +311,17 @@ pub fn sgr(self: *Screen, seq: ansi.CSI) void { } pub fn cursorLeft(self: *Screen, n: usize) void { - // default to 1, max of current cursor location - const cnt = @min(self.cursor.col, @max(n, 1)); - self.cursor.pending_wrap = false; - self.cursor.col -= cnt; + if (self.withinScrollingRegion()) + self.cursor.col = @max( + self.cursor.col -| n, + self.scrolling_region.left, + ) + else + self.cursor.col = @max( + self.cursor.col -| n, + 0, + ); } pub fn eraseRight(self: *Screen) void { diff --git a/src/widgets/terminal/Terminal.zig b/src/widgets/terminal/Terminal.zig index e20b085..7f53913 100644 --- a/src/widgets/terminal/Terminal.zig +++ b/src/widgets/terminal/Terminal.zig @@ -281,21 +281,11 @@ fn run(self: *Terminal) !void { self.back_screen.width, ); }, - 'D' => { + 'D', 'j' => { self.back_screen.cursor.pending_wrap = false; var iter = seq.iterator(u16); const delta = iter.next() orelse 1; - const within = self.back_screen.withinScrollingRegion(); - if (within) - self.back_screen.cursor.col = @max( - self.back_screen.cursor.col -| delta, - self.back_screen.scrolling_region.left, - ) - else - self.back_screen.cursor.col = @max( - self.back_screen.cursor.col -| delta, - 0, - ); + self.back_screen.cursorLeft(delta); }, 'H', 'f' => { // CUP var iter = seq.iterator(u16);