From ff43609097f19777c94defa1eab9f846deb515ba Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Thu, 11 Jul 2024 18:57:36 -0700 Subject: [PATCH] terminal: boilerplate for tmux control mode parsing --- src/terminal/dcs.zig | 19 +++++++++++++++++++ src/termio/Exec.zig | 6 ++++++ 2 files changed, 25 insertions(+) diff --git a/src/terminal/dcs.zig b/src/terminal/dcs.zig index 41ec28931..06e4d9437 100644 --- a/src/terminal/dcs.zig +++ b/src/terminal/dcs.zig @@ -98,6 +98,8 @@ pub const Handler = struct { .ignore, => {}, + .tmux => {}, + .xtgettcap => |*list| { if (list.items.len >= self.max_bytes) { return error.OutOfMemory; @@ -126,6 +128,8 @@ pub const Handler = struct { .ignore, => null, + .tmux => null, + .xtgettcap => |list| .{ .xtgettcap = .{ .data = list } }, .decrqss => |buffer| .{ .decrqss = switch (buffer.len) { @@ -157,6 +161,8 @@ pub const Handler = struct { .xtgettcap => |*list| list.deinit(), .decrqss => {}, + + .tmux => {}, } self.state = .{ .inactive = {} }; @@ -170,10 +176,14 @@ pub const Command = union(enum) { /// DECRQSS decrqss: DECRQSS, + /// Tmux control mode + tmux: Tmux, + pub fn deinit(self: Command) void { switch (self) { .xtgettcap => |*v| v.data.deinit(), .decrqss => {}, + .tmux => {}, } } @@ -207,6 +217,12 @@ pub const Command = union(enum) { decstbm, decslrm, }; + + /// Tmux control mode + pub const Tmux = union(enum) { + enter: void, + exit: void, + }; }; const State = union(enum) { @@ -225,6 +241,9 @@ const State = union(enum) { data: [2]u8 = undefined, len: u2 = 0, }, + + /// Tmux control mode: https://github.com/tmux/tmux/wiki/Control-Mode + tmux: void, }; test "unknown DCS command" { diff --git a/src/termio/Exec.zig b/src/termio/Exec.zig index a861bee6a..b0f973b1e 100644 --- a/src/termio/Exec.zig +++ b/src/termio/Exec.zig @@ -1880,6 +1880,11 @@ const StreamHandler = struct { fn dcsCommand(self: *StreamHandler, cmd: *terminal.dcs.Command) !void { // log.warn("DCS command: {}", .{cmd}); switch (cmd.*) { + .tmux => |tmux| { + // TODO: process it + log.warn("tmux control mode event unimplemented cmd={}", .{tmux}); + }, + .xtgettcap => |*gettcap| { const map = comptime terminfo.ghostty.xtgettcapMap(); while (gettcap.next()) |key| { @@ -1887,6 +1892,7 @@ const StreamHandler = struct { self.messageWriter(.{ .write_stable = response }); } }, + .decrqss => |decrqss| { var response: [128]u8 = undefined; var stream = std.io.fixedBufferStream(&response);