termio: hook up dcs callbacks

This commit is contained in:
Mitchell Hashimoto
2023-09-27 13:32:00 -07:00
parent 032fcee9ff
commit 823f47f695
2 changed files with 29 additions and 4 deletions

View File

@ -67,8 +67,12 @@ pub fn Stream(comptime Handler: type) type {
.dcs_hook => |dcs| if (@hasDecl(T, "dcsHook")) { .dcs_hook => |dcs| if (@hasDecl(T, "dcsHook")) {
try self.handler.dcsHook(dcs); try self.handler.dcsHook(dcs);
} else log.warn("unimplemented DCS hook", .{}), } else log.warn("unimplemented DCS hook", .{}),
.dcs_put => |code| log.warn("unhandled DCS put: {x}", .{code}), .dcs_put => |code| if (@hasDecl(T, "dcsPut")) {
.dcs_unhook => log.warn("unhandled DCS unhook", .{}), try self.handler.dcsPut(code);
} else log.warn("unimplemented DCS put: {x}", .{code}),
.dcs_unhook => if (@hasDecl(T, "dcsUnhook")) {
try self.handler.dcsUnhook();
} else log.warn("unimplemented DCS unhook", .{}),
.apc_start => if (@hasDecl(T, "apcStart")) { .apc_start => if (@hasDecl(T, "apcStart")) {
try self.handler.apcStart(); try self.handler.apcStart();
} else log.warn("unimplemented APC start", .{}), } else log.warn("unimplemented APC start", .{}),

View File

@ -1157,6 +1157,11 @@ const StreamHandler = struct {
/// the kitty graphics protocol. /// the kitty graphics protocol.
apc: terminal.apc.Handler = .{}, apc: terminal.apc.Handler = .{},
/// The DCS handler maintains DCS state. DCS is like CSI or OSC,
/// but requires more stateful parsing. This is used by functionality
/// such as XTGETTCAP.
dcs: terminal.dcs.Handler = .{},
/// This is set to true when a message was written to the writer /// This is set to true when a message was written to the writer
/// mailbox. This can be used by callers to determine if they need /// mailbox. This can be used by callers to determine if they need
/// to wake up the writer. /// to wake up the writer.
@ -1173,6 +1178,7 @@ const StreamHandler = struct {
pub fn deinit(self: *StreamHandler) void { pub fn deinit(self: *StreamHandler) void {
self.apc.deinit(); self.apc.deinit();
self.dcs.deinit();
} }
inline fn queueRender(self: *StreamHandler) !void { inline fn queueRender(self: *StreamHandler) !void {
@ -1200,8 +1206,23 @@ const StreamHandler = struct {
} }
pub fn dcsHook(self: *StreamHandler, dcs: terminal.DCS) !void { pub fn dcsHook(self: *StreamHandler, dcs: terminal.DCS) !void {
_ = self; self.dcs.hook(self.alloc, dcs);
log.warn("DCS HOOK: {}", .{dcs}); }
pub fn dcsPut(self: *StreamHandler, byte: u8) !void {
self.dcs.put(byte);
}
pub fn dcsUnhook(self: *StreamHandler) !void {
var cmd = self.dcs.unhook() orelse return;
cmd.deinit();
// log.warn("DCS command: {}", .{cmd});
switch (cmd) {
.xtgettcap => |gettcap| {
_ = gettcap;
},
}
} }
pub fn apcStart(self: *StreamHandler) !void { pub fn apcStart(self: *StreamHandler) !void {