From b64f49a0d7de72dffde02369c81cd94052a2e6db Mon Sep 17 00:00:00 2001 From: Qwerasd Date: Mon, 7 Apr 2025 13:31:51 -0600 Subject: [PATCH] fix(kittygfx): accept commands with no control data This sort of command is treated as valid by Kitty so we should too. In fact, it occurs with the example `send-png` script provided in the docs for the protocol. --- src/terminal/kitty/graphics_command.zig | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/terminal/kitty/graphics_command.zig b/src/terminal/kitty/graphics_command.zig index 840949d74..61ba33a4d 100644 --- a/src/terminal/kitty/graphics_command.zig +++ b/src/terminal/kitty/graphics_command.zig @@ -98,6 +98,12 @@ pub const Parser = struct { self.state = .control_value; }, + // This can be encountered if we have a sequence with no + // control data, only payload data (i.e. "\x1b_G;"). + // + // Kitty treats this as valid so we do as well. + ';' => self.state = .data, + else => try self.accumulateValue(c, .control_key_ignore), }, @@ -1053,6 +1059,21 @@ test "delete command" { try testing.expectEqual(@as(u32, 4), dv.y); } +test "no control data" { + const testing = std.testing; + const alloc = testing.allocator; + var p = Parser.init(alloc); + defer p.deinit(); + + const input = ";QUFBQQ"; + for (input) |c| try p.feed(c); + const command = try p.complete(); + defer command.deinit(alloc); + + try testing.expect(command.control == .transmit); + try testing.expectEqualStrings("AAAA", command.data); +} + test "ignore unknown keys (long)" { const testing = std.testing; const alloc = testing.allocator;