terminal: boilerplate for tmux control mode parsing

This commit is contained in:
Mitchell Hashimoto
2024-07-11 18:57:36 -07:00
parent f375bf009c
commit ff43609097
2 changed files with 25 additions and 0 deletions

View File

@ -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" {

View File

@ -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);