diff --git a/src/Window.zig b/src/Window.zig index 6583f2789..8e04e7e42 100644 --- a/src/Window.zig +++ b/src/Window.zig @@ -706,13 +706,7 @@ pub fn setCursorUp(self: *Window, amount: u16) !void { } pub fn setCursorCol(self: *Window, col: u16) !void { - if (self.terminal.modes.origin == 1) { - // TODO - log.err("setCursorCol: implement origin mode", .{}); - unreachable; - } - - self.terminal.setCursorPos(self.terminal.screen.cursor.y + 1, col); + self.terminal.setCursorColAbsolute(col); } pub fn setCursorRow(self: *Window, row: u16) !void { diff --git a/src/terminal/Terminal.zig b/src/terminal/Terminal.zig index 708bd60bc..c224367da 100644 --- a/src/terminal/Terminal.zig +++ b/src/terminal/Terminal.zig @@ -463,6 +463,21 @@ pub fn setCursorPos(self: *Terminal, row_req: usize, col_req: usize) void { self.screen.cursor.pending_wrap = false; } +/// Move the cursor to column `col_req` (1-indexed) without modifying the row. +/// If `col_req` is 0, it is changed to 1. If `col_req` is greater than the +/// total number of columns, it is set to the right-most column. +/// +/// If cursor origin mode is set, the cursor row will be set inside the +/// current scroll region. +pub fn setCursorColAbsolute(self: *Terminal, col_req: usize) void { + // TODO: test + + assert(self.modes.origin == 0); // TODO + + const col = if (col_req == 0) 1 else col_req; + self.screen.cursor.x = @minimum(self.cols, col) - 1; +} + /// Erase the display. /// TODO: test pub fn eraseDisplay(