From 43a714de0c28afb3e4ca25508a28ae40a74c2690 Mon Sep 17 00:00:00 2001 From: Tim Culverhouse Date: Wed, 5 Jun 2024 11:49:03 -0500 Subject: [PATCH] parser: fix query responses for kitty kbd, decrpm --- src/Parser.zig | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/Parser.zig b/src/Parser.zig index 739ad13..b2a5dd7 100644 --- a/src/Parser.zig +++ b/src/Parser.zig @@ -290,11 +290,13 @@ inline fn parseOsc(input: []const u8, paste_allocator: ?std.mem.Allocator) !Resu inline fn parseCsi(input: []const u8, text_buf: []u8) Result { // We start iterating at index 2 to get past te '[' const sequence = for (input[2..], 2..) |b, i| { + if (i == 2 and b == '?') continue; switch (b) { 0x40...0xFF => break input[0 .. i + 1], else => continue, } } else return .{ .event = null, .n = 0 }; + std.log.err("{s}\r\n", .{sequence[1..]}); const null_event: Result = .{ .event = null, .n = sequence.len }; @@ -431,6 +433,11 @@ inline fn parseCsi(input: []const u8, text_buf: []u8) Result { // Not all fields will be present. Only unicode-key-code is // mandatory + if (sequence.len > 2 and sequence[2] == '?') return .{ + .event = .cap_kitty_keyboard, + .n = sequence.len, + }; + var key: Key = .{ .codepoint = undefined, }; @@ -487,10 +494,10 @@ inline fn parseCsi(input: []const u8, text_buf: []u8) Result { return .{ .event = event, .n = sequence.len }; }, 'y' => { - // DECRPM (CSI Ps ; Pm y) + // DECRPM (CSI ? Ps ; Pm $ y) const delim_idx = std.mem.indexOfScalarPos(u8, input, 2, ';') orelse return null_event; - const ps = std.fmt.parseUnsigned(u16, input[2..delim_idx], 10) catch return null_event; - const pm = std.fmt.parseUnsigned(u8, input[delim_idx + 1 .. sequence.len - 1], 10) catch return null_event; + const ps = std.fmt.parseUnsigned(u16, input[3..delim_idx], 10) catch return null_event; + const pm = std.fmt.parseUnsigned(u8, input[delim_idx + 1 .. sequence.len - 2], 10) catch return null_event; switch (ps) { // Mouse Pixel reporting 1016 => switch (pm) {