widgets(terminal): implement CNL

This commit is contained in:
Tim Culverhouse 2024-06-10 06:00:20 -05:00
parent 99ff37840d
commit 1c5ecae8f0
2 changed files with 19 additions and 19 deletions

View file

@ -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 { pub fn cursorLeft(self: *Screen, n: usize) void {
self.cursor.pending_wrap = false; self.cursor.pending_wrap = false;
if (self.withinScrollingRegion()) 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;
}

View file

@ -260,16 +260,9 @@ fn run(self: *Terminal) !void {
switch (seq.final) { switch (seq.final) {
// Cursor up // Cursor up
'A', 'k' => { 'A', 'k' => {
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;
if (self.back_screen.withinScrollingRegion()) self.back_screen.cursorUp(delta);
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;
}, },
// Cursor Down // Cursor Down
'B' => { 'B' => {
@ -296,7 +289,6 @@ fn run(self: *Terminal) !void {
}, },
// Cursor Left // Cursor Left
'D', 'j' => { 'D', 'j' => {
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;
self.back_screen.cursorLeft(delta); self.back_screen.cursorLeft(delta);
@ -308,6 +300,13 @@ fn run(self: *Terminal) !void {
self.back_screen.cursorDown(delta); self.back_screen.cursorDown(delta);
self.carriageReturn(); 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' => { 'H', 'f' => {
var iter = seq.iterator(u16); var iter = seq.iterator(u16);
const row = iter.next() orelse 1; const row = iter.next() orelse 1;