MCPcopy Index your code
hub / github.com/codeaashu/claude-code / parseKeypress

Function parseKeypress

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

Source from the content-addressed store, hash-verified

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