MCPcopy Create free account
hub / github.com/Noumena-Network/code / parseKeypress

Function parseKeypress

src/ink/parse-keypress.ts:615–805  ·  view source on GitHub ↗
(s: string = '')

Source from the content-addressed store, hash-verified

613}
614
615function parseKeypress(s: string = ''): ParsedKey {
616 let parts
617
618 const key: ParsedKey = {
619 kind: 'key',
620 name: '',
621 fn: false,
622 ctrl: false,
623 meta: false,
624 shift: false,
625 option: false,
626 super: false,
627 sequence: s,
628 raw: s,
629 isPasted: false,
630 }
631
632 key.sequence = key.sequence || s || key.name
633
634 // Handle CSI u (kitty keyboard protocol): ESC [ codepoint [; modifier] u
635 // Example: ESC[13;2u = Shift+Enter, ESC[27u = Escape (no modifiers)
636 let match: RegExpExecArray | null
637 if ((match = CSI_U_RE.exec(s))) {
638 const codepoint = parseInt(match[1]!, 10)
639 // Modifier defaults to 1 (no modifiers) when not present
640 const modifier = match[2] ? parseInt(match[2], 10) : 1
641 const mods = decodeModifier(modifier)
642 const name = keycodeToName(codepoint)
643 return {
644 kind: 'key',
645 name,
646 fn: false,
647 ctrl: mods.ctrl,
648 meta: mods.meta,
649 shift: mods.shift,
650 option: false,
651 super: mods.super,
652 sequence: s,
653 raw: s,
654 isPasted: false,
655 }
656 }
657
658 // Handle xterm modifyOtherKeys: ESC [ 27 ; modifier ; keycode ~
659 // Must run before FN_KEY_RE — FN_KEY_RE only allows 2 params before ~ and
660 // would leave the tail as garbage if it partially matched.
661 if ((match = MODIFY_OTHER_KEYS_RE.exec(s))) {
662 const mods = decodeModifier(parseInt(match[1]!, 10))
663 const name = keycodeToName(parseInt(match[2]!, 10))
664 return {
665 kind: 'key',
666 name,
667 fn: false,
668 ctrl: mods.ctrl,
669 meta: mods.meta,
670 shift: mods.shift,
671 option: false,
672 super: mods.super,

Callers 1

parseMultipleKeypressesFunction · 0.85

Calls 5

decodeModifierFunction · 0.85
keycodeToNameFunction · 0.85
createNavKeyFunction · 0.85
isShiftKeyFunction · 0.85
isCtrlKeyFunction · 0.85

Tested by

no test coverage detected