diff --git a/src/widgets/terminal/Screen.zig b/src/widgets/terminal/Screen.zig index bc3a325..d3df6a5 100644 --- a/src/widgets/terminal/Screen.zig +++ b/src/widgets/terminal/Screen.zig @@ -310,6 +310,17 @@ pub fn sgr(self: *Screen, seq: ansi.CSI) void { } } +pub fn cursorUp(self: *Screen, n: usize) void { + self.cursor.pending_wrap = false; + if (self.withinScrollingRegion()) + self.cursor.row = @max( + self.cursor.row -| n, + self.scrolling_region.top, + ) + else + self.cursor.row -|= n; +} + pub fn cursorLeft(self: *Screen, n: usize) void { self.cursor.pending_wrap = false; if (self.withinScrollingRegion()) @@ -395,13 +406,3 @@ pub fn insertLine(self: *Screen, n: usize) !void { } } } - -pub fn carriageReturn(self: *Screen) void { - self.cursor.pending_wrap = false; - self.cursor.col = if (self.mode.origin) - self.scrolling_region.left - else if (self.cursor.col >= self.scrolling_region.left) - self.scrolling_region.left - else - 0; -} diff --git a/src/widgets/terminal/Terminal.zig b/src/widgets/terminal/Terminal.zig index 6da18fd..ffa03e4 100644 --- a/src/widgets/terminal/Terminal.zig +++ b/src/widgets/terminal/Terminal.zig @@ -260,16 +260,9 @@ fn run(self: *Terminal) !void { switch (seq.final) { // Cursor up 'A', 'k' => { - self.back_screen.cursor.pending_wrap = false; var iter = seq.iterator(u16); const delta = iter.next() orelse 1; - 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; + self.back_screen.cursorUp(delta); }, // Cursor Down 'B' => { @@ -296,7 +289,6 @@ fn run(self: *Terminal) !void { }, // Cursor Left 'D', 'j' => { - self.back_screen.cursor.pending_wrap = false; var iter = seq.iterator(u16); const delta = iter.next() orelse 1; self.back_screen.cursorLeft(delta); @@ -308,6 +300,13 @@ fn run(self: *Terminal) !void { self.back_screen.cursorDown(delta); self.carriageReturn(); }, + // Cursor Previous Line + 'F' => { + var iter = seq.iterator(u16); + const delta = iter.next() orelse 1; + self.back_screen.cursorUp(delta); + self.carriageReturn(); + }, 'H', 'f' => { var iter = seq.iterator(u16); const row = iter.next() orelse 1;