diff --git a/src/terminal/Parser.zig b/src/terminal/Parser.zig index 0615714af..3c7b5bd65 100644 --- a/src/terminal/Parser.zig +++ b/src/terminal/Parser.zig @@ -63,11 +63,19 @@ pub const Action = union(enum) { /// structure are only valid until the next call to "next". csi_dispatch: CSI, + /// Execute the ESC command. + esc_dispatch: ESC, + pub const CSI = struct { intermediates: []u8, params: []u16, final: u8, }; + + pub const ESC = struct { + intermediates: []u8, + final: u8, + }; }; /// Maximum number of intermediate characters during parsing. @@ -192,6 +200,12 @@ fn doAction(self: *Parser, action: TransitionAction, c: u8) ?Action { }, }; }, + .esc_dispatch => Action{ + .esc_dispatch = .{ + .intermediates = self.intermediates[0..self.intermediates_idx], + .final = c, + }, + }, else => { std.log.err("unimplemented action: {}", .{action}); @panic("TODO"); diff --git a/src/terminal/Terminal.zig b/src/terminal/Terminal.zig index aa1444b17..a38b917e8 100644 --- a/src/terminal/Terminal.zig +++ b/src/terminal/Terminal.zig @@ -129,6 +129,7 @@ pub fn appendChar(self: *Terminal, alloc: Allocator, c: u8) !void { .print => |p| try self.print(alloc, p), .execute => |code| try self.execute(alloc, code), .csi_dispatch => |csi| try self.csiDispatch(alloc, csi), + .esc_dispatch => |esc| log.warn("unhandled esc: {}", .{esc}), } } } @@ -289,7 +290,13 @@ pub fn eraseLine( ) !void { switch (mode) { .right => { + // If our cursor is outside our screen, we can't erase anything. + if (self.cursor.y >= self.screen.items.len) return; var line = &self.screen.items[self.cursor.y]; + + // If our cursor is outside our screen, we can't erase anything. + if (self.cursor.x >= line.items.len) return; + for (line.items[self.cursor.x..line.items.len]) |*cell| cell.char = 0; },