- commit
- d0e3ed1
- parent
- e9729b9
- author
- Eric Bower
- date
- 2026-04-03 14:14:03 -0400 EDT
refactor: generic parsing kitty ctrl key fns
1 files changed,
+10,
-6
+10,
-6
1@@ -220,25 +220,29 @@ pub fn findTaskExitMarker(output: []const u8) ?u8 {
2 /// and alternate key sub-fields from the kitty protocol's progressive
3 /// enhancement flags.
4 pub fn isKittyCtrlBackslash(buf: []const u8) bool {
5- // Scan for any CSI u sequence encoding Ctrl+\ in the buffer.
6+ return isKittyCtrlKey(buf, 92);
7+}
8+
9+fn isKittyCtrlKey(buf: []const u8, key_code: u32) bool {
10+ // Scan for any CSI u sequence encoding the given Ctrl+key in the buffer.
11 // The sequence can appear at any offset (e.g. preceded by other input).
12 var i: usize = 0;
13 while (i + 2 < buf.len) : (i += 1) {
14 if (buf[i] == 0x1b and buf[i + 1] == '[') {
15- if (parseKittyCtrlBackslash(buf[i + 2 ..])) return true;
16+ if (parseKittyCtrlKey(buf[i + 2 ..], key_code)) return true;
17 }
18 }
19 return false;
20 }
21
22 /// Parse a CSI u sequence (after the `\x1b[` prefix) and return true if it
23-/// encodes a Ctrl+\ press or repeat event.
24-fn parseKittyCtrlBackslash(buf: []const u8) bool {
25+/// encodes a Ctrl+key press or repeat event for the given key code.
26+fn parseKittyCtrlKey(buf: []const u8, expected_key: u32) bool {
27 var pos: usize = 0;
28
29- // 1. Parse key code -- must be 92 (backslash).
30+ // 1. Parse key code.
31 const key_code = parseDecimal(buf, &pos) orelse return false;
32- if (key_code != 92) return false;
33+ if (key_code != expected_key) return false;
34
35 // 2. Skip any ':alternate-key' sub-fields (shifted key, base layout key).
36 while (pos < buf.len and buf[pos] == ':') {