From 54783e362492496b7cbee7e78d59c443711d38f6 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Sun, 8 May 2022 20:42:24 -0700 Subject: [PATCH] cursor right --- src/terminal/Terminal.zig | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/src/terminal/Terminal.zig b/src/terminal/Terminal.zig index b46309a8a..aa1444b17 100644 --- a/src/terminal/Terminal.zig +++ b/src/terminal/Terminal.zig @@ -139,6 +139,16 @@ fn csiDispatch( action: Parser.Action.CSI, ) !void { switch (action.final) { + // CUF - Cursor Right + 'C' => self.cursorRight(switch (action.params.len) { + 0 => 1, + 1 => action.params[0], + else => { + log.warn("invalid cursor right command: {}", .{action}); + return; + }, + }), + // CUP - Set Cursor Position. 'H' => { switch (action.params.len) { @@ -319,6 +329,21 @@ pub fn deleteChars(self: *Terminal, count: usize) !void { } } +/// 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 +/// 0, adjust it to 1. +/// TODO: test +pub fn cursorRight(self: *Terminal, count: usize) void { + const tracy = trace(@src()); + defer tracy.end(); + + self.cursor.x += count; + if (self.cursor.x == self.cols) { + self.cursor.x -= 1; + } +} + /// Backspace moves the cursor back a column (but not less than 0). pub fn backspace(self: *Terminal) void { const tracy = trace(@src());