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 { | |
| 220 | 220 | /// and alternate key sub-fields from the kitty protocol's progressive | |
| 221 | 221 | /// enhancement flags. | |
| 222 | 222 | 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. | |
| 224 | 228 | // The sequence can appear at any offset (e.g. preceded by other input). | |
| 225 | 229 | var i: usize = 0; | |
| 226 | 230 | while (i + 2 < buf.len) : (i += 1) { | |
| 227 | 231 | 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; | |
| 229 | 233 | } | |
| 230 | 234 | } | |
| 231 | 235 | return false; | |
| 232 | 236 | } | |
| 233 | 237 | ||
| 234 | 238 | /// 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 { | |
| 237 | 241 | var pos: usize = 0; | |
| 238 | 242 | ||
| 239 | - | // 1. Parse key code -- must be 92 (backslash). | |
| 243 | + | // 1. Parse key code. | |
| 240 | 244 | const key_code = parseDecimal(buf, &pos) orelse return false; | |
| 241 | - | if (key_code != 92) return false; | |
| 245 | + | if (key_code != expected_key) return false; | |
| 242 | 246 | ||
| 243 | 247 | // 2. Skip any ':alternate-key' sub-fields (shifted key, base layout key). | |
| 244 | 248 | while (pos < buf.len and buf[pos] == ':') { |