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

Function parseTerminalResponse

source code/ink/parse-keypress.ts:124–177  ·  view source on GitHub ↗

* Try to recognize a sequence token as a terminal response. * Returns null if the sequence is not a known response pattern * (i.e. it should be treated as a keypress). * * These patterns are syntactically distinguishable from keyboard input — * no physical key produces CSI ? ... c or CSI ? ...

(s: string)

Source from the content-addressed store, hash-verified

122 * safely parsed out of the input stream at any time.
123 */
124function parseTerminalResponse(s: string): TerminalResponse | null {
125 // CSI-prefixed responses
126 if (s.startsWith('\x1b[')) {
127 let m: RegExpExecArray | null
128
129 if ((m = DECRPM_RE.exec(s))) {
130 return {
131 type: 'decrpm',
132 mode: parseInt(m[1]!, 10),
133 status: parseInt(m[2]!, 10),
134 }
135 }
136
137 if ((m = DA1_RE.exec(s))) {
138 return { type: 'da1', params: splitNumericParams(m[1]!) }
139 }
140
141 if ((m = DA2_RE.exec(s))) {
142 return { type: 'da2', params: splitNumericParams(m[1]!) }
143 }
144
145 if ((m = KITTY_FLAGS_RE.exec(s))) {
146 return { type: 'kittyKeyboard', flags: parseInt(m[1]!, 10) }
147 }
148
149 if ((m = CURSOR_POSITION_RE.exec(s))) {
150 return {
151 type: 'cursorPosition',
152 row: parseInt(m[1]!, 10),
153 col: parseInt(m[2]!, 10),
154 }
155 }
156
157 return null
158 }
159
160 // OSC responses (e.g. OSC 11 ; rgb:... for bg color query)
161 if (s.startsWith('\x1b]')) {
162 const m = OSC_RESPONSE_RE.exec(s)
163 if (m) {
164 return { type: 'osc', code: parseInt(m[1]!, 10), data: m[2]! }
165 }
166 }
167
168 // DCS responses (e.g. XTVERSION: DCS > | name ST)
169 if (s.startsWith('\x1bP')) {
170 const m = XTVERSION_RE.exec(s)
171 if (m) {
172 return { type: 'xtversion', name: m[1]! }
173 }
174 }
175
176 return null
177}
178
179function splitNumericParams(params: string): number[] {
180 if (!params) return []

Callers 1

parseMultipleKeypressesFunction · 0.85

Calls 1

splitNumericParamsFunction · 0.85

Tested by

no test coverage detected