MCPcopy Create free account
hub / github.com/AnukarOP/claude-code-leaked / parseKeypress

Function parseKeypress

source code/ink/parse-keypress.ts:613–787  ·  view source on GitHub ↗
(s: string = '')

Source from the content-addressed store, hash-verified

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