terminal: parse APC strings

This commit is contained in:
Mitchell Hashimoto
2023-08-18 13:34:40 -07:00
parent 3ca759bac6
commit 29e3e79b94
3 changed files with 18 additions and 8 deletions

View File

@ -48,6 +48,7 @@ pub const TransitionAction = enum {
csi_dispatch,
put,
osc_put,
apc_put,
};
/// Action is the action that a caller of the parser is expected to
@ -74,6 +75,11 @@ pub const Action = union(enum) {
dcs_put: u8,
dcs_unhook: void,
/// APC data
apc_start: void,
apc_put: u8,
apc_end: void,
pub const CSI = struct {
intermediates: []u8,
params: []u16,
@ -247,6 +253,7 @@ pub fn next(self: *Parser, c: u8) [3]?Action {
else
null,
.dcs_passthrough => Action{ .dcs_unhook = {} },
.sos_pm_apc_string => Action{ .apc_end = {} },
else => null,
},
@ -269,6 +276,7 @@ pub fn next(self: *Parser, c: u8) [3]?Action {
.final = c,
},
},
.sos_pm_apc_string => Action{ .apc_start = {} },
.utf8 => utf8: {
// When entering the UTF8 state, we need to grab the
// last intermediate as our first byte and reset
@ -426,9 +434,8 @@ fn doAction(self: *Parser, action: TransitionAction, c: u8) ?Action {
.final = c,
},
},
.put => Action{
.dcs_put = c,
},
.put => Action{ .dcs_put = c },
.apc_put => Action{ .apc_put = c },
};
}

View File

@ -125,10 +125,10 @@ fn genTable() Table {
const source = State.sos_pm_apc_string;
// events
single(&result, 0x19, source, source, .ignore);
range(&result, 0, 0x17, source, source, .ignore);
range(&result, 0x1C, 0x1F, source, source, .ignore);
range(&result, 0x20, 0x7F, source, source, .ignore);
single(&result, 0x19, source, source, .apc_put);
range(&result, 0, 0x17, source, source, .apc_put);
range(&result, 0x1C, 0x1F, source, source, .apc_put);
range(&result, 0x20, 0x7F, source, source, .apc_put);
}
// escape

View File

@ -64,8 +64,11 @@ pub fn Stream(comptime Handler: type) type {
.esc_dispatch => |esc| try self.escDispatch(esc),
.osc_dispatch => |cmd| try self.oscDispatch(cmd),
.dcs_hook => |dcs| log.warn("unhandled DCS hook: {}", .{dcs}),
.dcs_put => |code| log.warn("unhandled DCS put: {}", .{code}),
.dcs_put => |code| log.warn("unhandled DCS put: {x}", .{code}),
.dcs_unhook => log.warn("unhandled DCS unhook", .{}),
.apc_start => log.warn("unhandled APC start", .{}),
.apc_put => |code| log.warn("unhandled APC put: {x}", .{code}),
.apc_end => log.warn("unhandled APC end", .{}),
}
}
}