From 823f47f69515d1b9f5ef1780a1ad8bae6bb122eb Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Wed, 27 Sep 2023 13:32:00 -0700 Subject: [PATCH] termio: hook up dcs callbacks --- src/terminal/stream.zig | 8 ++++++-- src/termio/Exec.zig | 25 +++++++++++++++++++++++-- 2 files changed, 29 insertions(+), 4 deletions(-) diff --git a/src/terminal/stream.zig b/src/terminal/stream.zig index debc12e0e..6e4ffb235 100644 --- a/src/terminal/stream.zig +++ b/src/terminal/stream.zig @@ -67,8 +67,12 @@ pub fn Stream(comptime Handler: type) type { .dcs_hook => |dcs| if (@hasDecl(T, "dcsHook")) { try self.handler.dcsHook(dcs); } else log.warn("unimplemented DCS hook", .{}), - .dcs_put => |code| log.warn("unhandled DCS put: {x}", .{code}), - .dcs_unhook => log.warn("unhandled DCS unhook", .{}), + .dcs_put => |code| if (@hasDecl(T, "dcsPut")) { + 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")) { try self.handler.apcStart(); } else log.warn("unimplemented APC start", .{}), diff --git a/src/termio/Exec.zig b/src/termio/Exec.zig index a0e7c1856..5ece318fb 100644 --- a/src/termio/Exec.zig +++ b/src/termio/Exec.zig @@ -1157,6 +1157,11 @@ const StreamHandler = struct { /// the kitty graphics protocol. 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 /// mailbox. This can be used by callers to determine if they need /// to wake up the writer. @@ -1173,6 +1178,7 @@ const StreamHandler = struct { pub fn deinit(self: *StreamHandler) void { self.apc.deinit(); + self.dcs.deinit(); } inline fn queueRender(self: *StreamHandler) !void { @@ -1200,8 +1206,23 @@ const StreamHandler = struct { } pub fn dcsHook(self: *StreamHandler, dcs: terminal.DCS) !void { - _ = self; - log.warn("DCS HOOK: {}", .{dcs}); + self.dcs.hook(self.alloc, 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 {