diff --git a/src/Window.zig b/src/Window.zig index 1799ecc32..ccab59479 100644 --- a/src/Window.zig +++ b/src/Window.zig @@ -547,6 +547,10 @@ pub fn carriageReturn(self: *Window) !void { self.terminal.carriageReturn(); } +pub fn setCursorLeft(self: *Window, amount: u16) !void { + self.terminal.cursorLeft(amount); +} + pub fn setCursorRight(self: *Window, amount: u16) !void { self.terminal.cursorRight(amount); } diff --git a/src/terminal/Terminal.zig b/src/terminal/Terminal.zig index 589196ebb..dcd55a991 100644 --- a/src/terminal/Terminal.zig +++ b/src/terminal/Terminal.zig @@ -358,6 +358,17 @@ pub fn eraseChars(self: *Terminal, alloc: Allocator, count: usize) !void { } } +/// Move the cursor to the left amount cells. If amount is 0, adjust it to 1. +/// TODO: test +pub fn cursorLeft(self: *Terminal, count: usize) void { + const tracy = trace(@src()); + defer tracy.end(); + + // TODO: scroll region, wrap + + self.cursor.x -|= if (count == 0) 1 else count; +} + /// Move the cursor right amount columns. If amount is greater than the /// maximum move distance then it is internally adjusted to the maximum. /// This sequence will not scroll the screen or scroll region. If amount is diff --git a/src/terminal/stream.zig b/src/terminal/stream.zig index 8b727eea4..9f539fa00 100644 --- a/src/terminal/stream.zig +++ b/src/terminal/stream.zig @@ -131,6 +131,18 @@ pub fn Stream(comptime Handler: type) type { }, ) else log.warn("unimplemented CSI callback: {}", .{action}), + // CUB - Cursor Left + 'D' => if (@hasDecl(T, "setCursorLeft")) try self.handler.setCursorLeft( + switch (action.params.len) { + 0 => 1, + 1 => action.params[0], + else => { + log.warn("invalid cursor left command: {}", .{action}); + return; + }, + }, + ) else log.warn("unimplemented CSI callback: {}", .{action}), + // HPA - Cursor Horizontal Position Absolute // TODO: test 'G', '`' => if (@hasDecl(T, "setCursorCol")) switch (action.params.len) {