widgets(terminal): simplify cursorLeft logic

This commit is contained in:
Tim Culverhouse 2024-06-09 20:57:49 -05:00
parent cc77c98d32
commit aa9e492b26
2 changed files with 12 additions and 16 deletions

View file

@ -311,11 +311,17 @@ pub fn sgr(self: *Screen, seq: ansi.CSI) void {
} }
pub fn cursorLeft(self: *Screen, n: usize) 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.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 { pub fn eraseRight(self: *Screen) void {

View file

@ -281,21 +281,11 @@ fn run(self: *Terminal) !void {
self.back_screen.width, self.back_screen.width,
); );
}, },
'D' => { 'D', 'j' => {
self.back_screen.cursor.pending_wrap = false; self.back_screen.cursor.pending_wrap = false;
var iter = seq.iterator(u16); var iter = seq.iterator(u16);
const delta = iter.next() orelse 1; const delta = iter.next() orelse 1;
const within = self.back_screen.withinScrollingRegion(); self.back_screen.cursorLeft(delta);
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,
);
}, },
'H', 'f' => { // CUP 'H', 'f' => { // CUP
var iter = seq.iterator(u16); var iter = seq.iterator(u16);