parser: handle parsing of apc, sos, pm strings

This lets us detect kitty graphics.

Signed-off-by: Tim Culverhouse <tim@timculverhouse.com>
This commit is contained in:
Tim Culverhouse 2024-01-31 06:59:34 -06:00
parent 23a00ede55
commit 8c8c592722
4 changed files with 50 additions and 5 deletions

View file

@ -444,6 +444,46 @@ pub fn parse(self: *Parser, input: []const u8) !Result {
}, },
} }
}, },
.apc => {
switch (b) {
0x1B => {
state = .ground;
// advance one more for the backslash
i += 1;
switch (input[start + 1]) {
'G' => {
return .{
.event = .cap_kitty_graphics,
.n = i + 1,
};
},
else => {
log.warn("unhandled apc: APC {s}", .{input[start + 1 .. i + 1]});
return .{
.event = null,
.n = i + 1,
};
},
}
},
else => {},
}
},
.sos, .pm => {
switch (b) {
0x1B => {
state = .ground;
// advance one more for the backslash
i += 1;
log.warn("unhandled sos/pm: SOS/PM {s}", .{input[start + 1 .. i + 1]});
return .{
.event = null,
.n = i + 1,
};
},
else => {},
}
},
else => {}, else => {},
} }
} }

View file

@ -178,9 +178,15 @@ pub fn run(
} }
}, },
.cap_kitty_keyboard => { .cap_kitty_keyboard => {
log.info("kitty capability detected", .{}); log.info("kitty keyboard capability detected", .{});
vx.caps.kitty_keyboard = true; vx.caps.kitty_keyboard = true;
}, },
.cap_kitty_graphics => {
if (!vx.caps.kitty_graphics) {
log.info("kitty graphics capability detected", .{});
vx.caps.kitty_graphics = true;
}
},
.cap_rgb => { .cap_rgb => {
log.info("rgb capability detected", .{}); log.info("rgb capability detected", .{});
vx.caps.rgb = true; vx.caps.rgb = true;

View file

@ -10,6 +10,7 @@ pub const Event = union(enum) {
// these are delivered as discovered terminal capabilities // these are delivered as discovered terminal capabilities
cap_kitty_keyboard, cap_kitty_keyboard,
cap_kitty_graphics,
cap_rgb, cap_rgb,
cap_unicode, cap_unicode,
cap_da1, cap_da1,

View file

@ -222,10 +222,7 @@ pub fn Vaxis(comptime T: type) type {
// that // that
// _ = try tty.write(ctlseqs.xtversion); // _ = try tty.write(ctlseqs.xtversion);
_ = try tty.write(ctlseqs.csi_u_query); _ = try tty.write(ctlseqs.csi_u_query);
// TODO: KITTY_GRAPHICS has an APC response. uncomment when we can _ = try tty.write(ctlseqs.kitty_graphics_query);
// parse that
// that
// _ = try tty.write(ctlseqs.kitty_graphics_query);
// TODO: sixel geometry query interferes with F4 keys. // TODO: sixel geometry query interferes with F4 keys.
// _ = try tty.write(ctlseqs.sixel_geometry_query); // _ = try tty.write(ctlseqs.sixel_geometry_query);
@ -590,6 +587,7 @@ pub fn Vaxis(comptime T: type) type {
alloc: std.mem.Allocator, alloc: std.mem.Allocator,
src: Image.Source, src: Image.Source,
) !Image { ) !Image {
if (!self.caps.kitty_graphics) return error.NoGraphicsCapability;
var tty = self.tty orelse return error.NoTTY; var tty = self.tty orelse return error.NoTTY;
defer self.next_img_id += 1; defer self.next_img_id += 1;