graff — a fast agentic coding harness in Zig: multi-provider, MCP, workflows, DGM evolution loop, TS/Python SDKs
Python
fix(tui): map the kitty keypad and read the event type from the right field
Rach Pradhan29d0f7906a27
diff --git a/TUI/key.zig b/TUI/key.zigindex a14cb535..c8fb5198 100644--- a/TUI/key.zig+++ b/TUI/key.zig@@ -374,11 +374,17 @@ fn csiMods(params: []const u8) u32 {}/// kitty event-type sub-param (field 2 after ':'): 1 press, 2 repeat, 3 release.+///+/// It lives in the MODIFIER field and nowhere else. Scanning the whole tail for+/// the first ':' read field 3 instead — the associated-text codepoints, which+/// are ':'-separated too — so `CSI 97;2;65:66u` reported event 66, and a text+/// field ending `:3` silently swallowed a real keypress as a release (#549).fn eventOf(params: []const u8) u32 {const s = std.mem.indexOfScalar(u8, params, ';') orelse return 1;- const rest = params[s + 1 ..];- const c = std.mem.indexOfScalar(u8, rest, ':') orelse return 1;- return leadingInt(rest[c + 1 ..]);+ var field = params[s + 1 ..];+ if (std.mem.indexOfScalar(u8, field, ';')) |e| field = field[0..e];+ const c = std.mem.indexOfScalar(u8, field, ':') orelse return 1;+ return leadingInt(field[c + 1 ..]);}/// CSI unicode ; mods u — kitty/ghostty. mods bit 2 = ctrl, 1 = shift.@@ -437,7 +443,20 @@ fn functional(code: u32, mods: u32, ev: u32) Key {57355, 57422 => .page_down,57356, 57423 => .home,57357, 57424 => .end,- // Locks, PrintScreen, remaining keypad, media, F13+: inert.+ // Numeric keypad. With `>11u` on, kitty reports these INSTEAD of the+ // plain ASCII byte, so leaving them unmapped dropped every keypad+ // digit and operator on the floor (#549).+ 57399...57408 => .{ .char = '0' + @as(u8, @intCast(code - 57399)) },+ 57409 => .{ .char = '.' },+ 57410 => .{ .char = '/' },+ 57411 => .{ .char = '*' },+ 57412 => .{ .char = '-' },+ 57413 => .{ .char = '+' },+ 57415 => .{ .char = '=' },+ 57416 => .{ .char = ',' },+ // KP_Insert (57425) and KP_Begin (57427) have no binding here and stay+ // inert exactly like CSI 2~ — never a phantom Escape. Locks,+ // PrintScreen, media and F13+ likewise.else => .ignore,};}diff --git a/TUI/key_tests.zig b/TUI/key_tests.zigindex 32e946ce..53f31ecc 100644--- a/TUI/key_tests.zig+++ b/TUI/key_tests.zig@@ -294,3 +294,48 @@ test "typed text behind an Alt+] chord recovers instead of wedging (#516)" {try std.testing.expectEqual(Key.ignore, next(&big, &i).?);try std.testing.expectEqual(Key{ .char = 'a' }, next(&big, &i).?);}+test "kitty numeric keypad types instead of vanishing (#549)" {+ var i: usize = 0;+ try std.testing.expectEqual(Key{ .char = '0' }, next("\x1b[57399u", &i).?);+ i = 0;+ try std.testing.expectEqual(Key{ .char = '7' }, next("\x1b[57406u", &i).?);+ i = 0;+ try std.testing.expectEqual(Key{ .char = '9' }, next("\x1b[57408u", &i).?);+ i = 0;+ try std.testing.expectEqual(Key{ .char = '.' }, next("\x1b[57409u", &i).?);+ i = 0;+ try std.testing.expectEqual(Key{ .char = '/' }, next("\x1b[57410u", &i).?);+ i = 0;+ try std.testing.expectEqual(Key{ .char = '*' }, next("\x1b[57411u", &i).?);+ i = 0;+ try std.testing.expectEqual(Key{ .char = '-' }, next("\x1b[57412u", &i).?);+ i = 0;+ try std.testing.expectEqual(Key{ .char = '+' }, next("\x1b[57413u", &i).?);+ i = 0;+ try std.testing.expectEqual(Key{ .char = '=' }, next("\x1b[57415u", &i).?);+ i = 0;+ try std.testing.expectEqual(Key{ .char = ',' }, next("\x1b[57416u", &i).?);+ // Releases stay inert, and the unbound keypad keys are still never Escape.+ i = 0;+ try std.testing.expectEqual(Key.ignore, next("\x1b[57406;1:3u", &i).?);+ i = 0;+ try std.testing.expectEqual(Key.ignore, next("\x1b[57425u", &i).?); // KP_Insert+ i = 0;+ try std.testing.expectEqual(Key.ignore, next("\x1b[57427u", &i).?); // KP_Begin+ key.held = 0;+}++test "the event type is read from the modifier field, not the text field (#549)" {+ // `CSI code ; mods:event ; text:text u` — the associated-text codepoints in+ // field 3 are ':'-separated too, and scanning the whole tail found those.+ var i: usize = 0;+ try std.testing.expectEqual(Key{ .char = 'A' }, next("\x1b[97;2;65:66u", &i).?);+ i = 0;+ try std.testing.expectEqual(Key{ .char = 'a' }, next("\x1b[97;1;97:3u", &i).?);+ // A genuine release, in field 2, is still ignored.+ i = 0;+ try std.testing.expectEqual(Key.ignore, next("\x1b[97;1:3u", &i).?);+ i = 0;+ try std.testing.expectEqual(Key.ignore, next("\x1b[1;1:3A", &i).?);+ key.held = 0;+}