(data: string, keyId: KeyId)
| 818 | * @param keyId - Key identifier (e.g., "ctrl+c", "escape", Key.ctrl("c")) |
| 819 | */ |
| 820 | export function matchesKey(data: string, keyId: KeyId): boolean { |
| 821 | const parsed = parseKeyId(keyId); |
| 822 | if (!parsed) return false; |
| 823 | |
| 824 | const { key, ctrl, shift, alt, super: superModifier } = parsed; |
| 825 | let modifier = 0; |
| 826 | if (shift) modifier |= MODIFIERS.shift; |
| 827 | if (alt) modifier |= MODIFIERS.alt; |
| 828 | if (ctrl) modifier |= MODIFIERS.ctrl; |
| 829 | if (superModifier) modifier |= MODIFIERS.super; |
| 830 | |
| 831 | switch (key) { |
| 832 | case "escape": |
| 833 | case "esc": |
| 834 | if (modifier !== 0) return false; |
| 835 | return ( |
| 836 | data === "\x1b" || |
| 837 | matchesKittySequence(data, CODEPOINTS.escape, 0) || |
| 838 | matchesModifyOtherKeys(data, CODEPOINTS.escape, 0) |
| 839 | ); |
| 840 | |
| 841 | case "space": |
| 842 | if (!_kittyProtocolActive) { |
| 843 | if (modifier === MODIFIERS.ctrl && data === "\x00") { |
| 844 | return true; |
| 845 | } |
| 846 | if (modifier === MODIFIERS.alt && data === "\x1b ") { |
| 847 | return true; |
| 848 | } |
| 849 | } |
| 850 | if (modifier === 0) { |
| 851 | return ( |
| 852 | data === " " || |
| 853 | matchesKittySequence(data, CODEPOINTS.space, 0) || |
| 854 | matchesModifyOtherKeys(data, CODEPOINTS.space, 0) |
| 855 | ); |
| 856 | } |
| 857 | return ( |
| 858 | matchesKittySequence(data, CODEPOINTS.space, modifier) || |
| 859 | matchesModifyOtherKeys(data, CODEPOINTS.space, modifier) |
| 860 | ); |
| 861 | |
| 862 | case "tab": |
| 863 | if (modifier === MODIFIERS.shift) { |
| 864 | return ( |
| 865 | data === "\x1b[Z" || |
| 866 | matchesKittySequence(data, CODEPOINTS.tab, MODIFIERS.shift) || |
| 867 | matchesModifyOtherKeys(data, CODEPOINTS.tab, MODIFIERS.shift) |
| 868 | ); |
| 869 | } |
| 870 | if (modifier === 0) { |
| 871 | return data === "\t" || matchesKittySequence(data, CODEPOINTS.tab, 0); |
| 872 | } |
| 873 | return ( |
| 874 | matchesKittySequence(data, CODEPOINTS.tab, modifier) || |
| 875 | matchesModifyOtherKeys(data, CODEPOINTS.tab, modifier) |
| 876 | ); |
| 877 |
no test coverage detected