MCPcopy Create free account
hub / github.com/anus-dev/ANUS / parseKittySequence

Function parseKittySequence

packages/cli/src/ui/contexts/KeypressContext.tsx:114–167  ·  view source on GitHub ↗
(sequence: string)

Source from the content-addressed store, hash-verified

112 let waitingForEnterAfterBackslash = false;
113
114 const parseKittySequence = (sequence: string): Key | null => {
115 const kittyPattern = new RegExp(`^${ESC}\\[(\\d+)(;(\\d+))?([u~])$`);
116 const match = sequence.match(kittyPattern);
117 if (!match) return null;
118
119 const keyCode = parseInt(match[1], 10);
120 const modifiers = match[3] ? parseInt(match[3], 10) : 1;
121 const modifierBits = modifiers - 1;
122 const shift = (modifierBits & 1) === 1;
123 const alt = (modifierBits & 2) === 2;
124 const ctrl = (modifierBits & 4) === 4;
125
126 if (keyCode === 27) {
127 return {
128 name: 'escape',
129 ctrl,
130 meta: alt,
131 shift,
132 paste: false,
133 sequence,
134 kittyProtocol: true,
135 };
136 }
137
138 if (
139 keyCode === KITTY_KEYCODE_ENTER ||
140 keyCode === KITTY_KEYCODE_NUMPAD_ENTER
141 ) {
142 return {
143 name: 'return',
144 ctrl,
145 meta: alt,
146 shift,
147 paste: false,
148 sequence,
149 kittyProtocol: true,
150 };
151 }
152
153 if (keyCode >= 97 && keyCode <= 122 && ctrl) {
154 const letter = String.fromCharCode(keyCode);
155 return {
156 name: letter,
157 ctrl: true,
158 meta: alt,
159 shift,
160 paste: false,
161 sequence,
162 kittyProtocol: true,
163 };
164 }
165
166 return null;
167 };
168
169 const broadcast = (key: Key) => {
170 for (const handler of subscribers) {

Callers 1

handleKeypressFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected