diff --git a/src/Parser.zig b/src/Parser.zig index 8e9f79c..3bf92bc 100644 --- a/src/Parser.zig +++ b/src/Parser.zig @@ -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 => {}, } } diff --git a/src/Tty.zig b/src/Tty.zig index 66a6c8d..c07746b 100644 --- a/src/Tty.zig +++ b/src/Tty.zig @@ -178,9 +178,15 @@ pub fn run( } }, .cap_kitty_keyboard => { - log.info("kitty capability detected", .{}); + log.info("kitty keyboard capability detected", .{}); 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 => { log.info("rgb capability detected", .{}); vx.caps.rgb = true; diff --git a/src/event.zig b/src/event.zig index 660c50d..e66d134 100644 --- a/src/event.zig +++ b/src/event.zig @@ -10,6 +10,7 @@ pub const Event = union(enum) { // these are delivered as discovered terminal capabilities cap_kitty_keyboard, + cap_kitty_graphics, cap_rgb, cap_unicode, cap_da1, diff --git a/src/vaxis.zig b/src/vaxis.zig index 0ca3001..24790ba 100644 --- a/src/vaxis.zig +++ b/src/vaxis.zig @@ -222,10 +222,7 @@ pub fn Vaxis(comptime T: type) type { // that // _ = try tty.write(ctlseqs.xtversion); _ = try tty.write(ctlseqs.csi_u_query); - // TODO: KITTY_GRAPHICS has an APC response. uncomment when we can - // parse that - // that - // _ = try tty.write(ctlseqs.kitty_graphics_query); + _ = try tty.write(ctlseqs.kitty_graphics_query); // TODO: sixel geometry query interferes with F4 keys. // _ = try tty.write(ctlseqs.sixel_geometry_query); @@ -590,6 +587,7 @@ pub fn Vaxis(comptime T: type) type { alloc: std.mem.Allocator, src: Image.Source, ) !Image { + if (!self.caps.kitty_graphics) return error.NoGraphicsCapability; var tty = self.tty orelse return error.NoTTY; defer self.next_img_id += 1;