diff --git a/src/terminal/Parser.zig b/src/terminal/Parser.zig index 8900b856c..0615714af 100644 --- a/src/terminal/Parser.zig +++ b/src/terminal/Parser.zig @@ -104,7 +104,7 @@ pub fn next(self: *Parser, c: u8) [3]?Action { break :effect table[c][@enumToInt(self.state)]; }; - log.info("next: {x}", .{c}); + // log.info("next: {x}", .{c}); const next_state = effect.state; const action = effect.action; diff --git a/src/terminal/Terminal.zig b/src/terminal/Terminal.zig index d3bc2560b..d9a0d5195 100644 --- a/src/terminal/Terminal.zig +++ b/src/terminal/Terminal.zig @@ -160,7 +160,7 @@ fn csiDispatch( } break :mode @intToEnum( - csi.EraseDisplayMode, + csi.EraseDisplay, action.params[0], ); }, @@ -170,6 +170,27 @@ fn csiDispatch( }, }), + // Erase Line + 'K' => try self.eraseLine(switch (action.params.len) { + 0 => .right, + 1 => mode: { + // TODO: use meta to get enum max + if (action.params[0] > 3) { + log.warn("invalid erase line command: {}", .{action}); + return; + } + + break :mode @intToEnum( + csi.EraseLine, + action.params[0], + ); + }, + else => { + log.warn("invalid erase line command: {}", .{action}); + return; + }, + }), + else => log.warn("unimplemented CSI: {}", .{action}), } } @@ -229,7 +250,7 @@ pub fn setCursorPosition(self: *Terminal, row: usize, col: usize) !void { pub fn eraseDisplay( self: *Terminal, alloc: Allocator, - mode: csi.EraseDisplayMode, + mode: csi.EraseDisplay, ) !void { switch (mode) { .complete => { @@ -240,6 +261,22 @@ pub fn eraseDisplay( } } +/// Erase the line. +/// TODO: test +pub fn eraseLine( + self: *Terminal, + mode: csi.EraseLine, +) !void { + switch (mode) { + .right => { + var line = &self.screen.items[self.cursor.y]; + for (line.items[self.cursor.x..line.items.len]) |*cell| + cell.char = 0; + }, + else => @panic("unimplemented"), + } +} + /// Backspace moves the cursor back a column (but not less than 0). pub fn backspace(self: *Terminal) void { const tracy = trace(@src()); diff --git a/src/terminal/csi.zig b/src/terminal/csi.zig index d4d237bc3..85d23a3b8 100644 --- a/src/terminal/csi.zig +++ b/src/terminal/csi.zig @@ -1,7 +1,15 @@ // Modes for the ED CSI command. -pub const EraseDisplayMode = enum(u8) { +pub const EraseDisplay = enum(u8) { below = 0, above = 1, complete = 2, scrollback = 3, }; + +// Modes for the EL CSI command. +pub const EraseLine = enum(u8) { + right = 0, + left = 1, + complete = 3, + right_unless_pending_wrap = 4, +};