esc dispatch is handled in parser

This commit is contained in:
Mitchell Hashimoto
2022-05-08 20:52:15 -07:00
parent 54783e3624
commit 86ab28cf10
2 changed files with 21 additions and 0 deletions

View File

@ -63,11 +63,19 @@ pub const Action = union(enum) {
/// structure are only valid until the next call to "next". /// structure are only valid until the next call to "next".
csi_dispatch: CSI, csi_dispatch: CSI,
/// Execute the ESC command.
esc_dispatch: ESC,
pub const CSI = struct { pub const CSI = struct {
intermediates: []u8, intermediates: []u8,
params: []u16, params: []u16,
final: u8, final: u8,
}; };
pub const ESC = struct {
intermediates: []u8,
final: u8,
};
}; };
/// Maximum number of intermediate characters during parsing. /// 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 => { else => {
std.log.err("unimplemented action: {}", .{action}); std.log.err("unimplemented action: {}", .{action});
@panic("TODO"); @panic("TODO");

View File

@ -129,6 +129,7 @@ pub fn appendChar(self: *Terminal, alloc: Allocator, c: u8) !void {
.print => |p| try self.print(alloc, p), .print => |p| try self.print(alloc, p),
.execute => |code| try self.execute(alloc, code), .execute => |code| try self.execute(alloc, code),
.csi_dispatch => |csi| try self.csiDispatch(alloc, csi), .csi_dispatch => |csi| try self.csiDispatch(alloc, csi),
.esc_dispatch => |esc| log.warn("unhandled esc: {}", .{esc}),
} }
} }
} }
@ -289,7 +290,13 @@ pub fn eraseLine(
) !void { ) !void {
switch (mode) { switch (mode) {
.right => { .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]; 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| for (line.items[self.cursor.x..line.items.len]) |*cell|
cell.char = 0; cell.char = 0;
}, },