widgets(terminal): handle scrolling_region in CUU, CUD

This commit is contained in:
Tim Culverhouse 2024-06-10 05:43:59 -05:00
parent 11ae2e7b29
commit 044b099227
2 changed files with 19 additions and 10 deletions

View file

@ -318,10 +318,7 @@ pub fn cursorLeft(self: *Screen, n: usize) void {
self.scrolling_region.left, self.scrolling_region.left,
) )
else else
self.cursor.col = @max( self.cursor.col = self.cursor.col -| n;
self.cursor.col -| n,
0,
);
} }
pub fn eraseRight(self: *Screen) void { pub fn eraseRight(self: *Screen) void {

View file

@ -255,18 +255,30 @@ fn run(self: *Terminal) !void {
.ss3 => |ss3| std.log.err("unhandled ss3: {c}", .{ss3}), .ss3 => |ss3| std.log.err("unhandled ss3: {c}", .{ss3}),
.csi => |seq| { .csi => |seq| {
switch (seq.final) { switch (seq.final) {
'A' => { 'A', 'k' => {
var iter = seq.iterator(u16); var iter = seq.iterator(u16);
const delta = iter.next() orelse 1; 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 'B' => { // CUD
var iter = seq.iterator(u16); var iter = seq.iterator(u16);
const delta = iter.next() orelse 1; const delta = iter.next() orelse 1;
self.back_screen.cursor.row = @min( if (self.back_screen.withinScrollingRegion())
self.back_screen.height - 1, self.back_screen.cursor.row = @min(
self.back_screen.cursor.row + delta, 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' => { 'C' => {
self.back_screen.cursor.pending_wrap = false; self.back_screen.cursor.pending_wrap = false;