Commit d0e3ed1

Eric Bower  ·  2026-04-03 14:14:03 -0400 EDT
parent e9729b9
refactor: generic parsing kitty ctrl key fns
1 files changed,  +10, -6
+10, -6
......@@ -220,25 +220,29 @@ pub fn findTaskExitMarker(output: []const u8) ?u8 {
220220 /// and alternate key sub-fields from the kitty protocol's progressive
221221 /// enhancement flags.
222222 pub fn isKittyCtrlBackslash(buf: []const u8) bool {
223- // Scan for any CSI u sequence encoding Ctrl+\ in the buffer.
223+ return isKittyCtrlKey(buf, 92);
224+}
225+
226+fn isKittyCtrlKey(buf: []const u8, key_code: u32) bool {
227+ // Scan for any CSI u sequence encoding the given Ctrl+key in the buffer.
224228 // The sequence can appear at any offset (e.g. preceded by other input).
225229 var i: usize = 0;
226230 while (i + 2 < buf.len) : (i += 1) {
227231 if (buf[i] == 0x1b and buf[i + 1] == '[') {
228- if (parseKittyCtrlBackslash(buf[i + 2 ..])) return true;
232+ if (parseKittyCtrlKey(buf[i + 2 ..], key_code)) return true;
229233 }
230234 }
231235 return false;
232236 }
233237
234238 /// Parse a CSI u sequence (after the `\x1b[` prefix) and return true if it
235-/// encodes a Ctrl+\ press or repeat event.
236-fn parseKittyCtrlBackslash(buf: []const u8) bool {
239+/// encodes a Ctrl+key press or repeat event for the given key code.
240+fn parseKittyCtrlKey(buf: []const u8, expected_key: u32) bool {
237241 var pos: usize = 0;
238242
239- // 1. Parse key code -- must be 92 (backslash).
243+ // 1. Parse key code.
240244 const key_code = parseDecimal(buf, &pos) orelse return false;
241- if (key_code != 92) return false;
245+ if (key_code != expected_key) return false;
242246
243247 // 2. Skip any ':alternate-key' sub-fields (shifted key, base layout key).
244248 while (pos < buf.len and buf[pos] == ':') {