MCPcopy Create free account
hub / github.com/MoonshotAI/kimi-code / process

Method process

packages/pi-tui/src/stdin-buffer.ts:287–387  ·  view source on GitHub ↗
(data: string | Buffer)

Source from the content-addressed store, hash-verified

285 }
286
287 public process(data: string | Buffer): void {
288 // Clear any pending timeout
289 if (this.timeout) {
290 clearTimeout(this.timeout);
291 this.timeout = null;
292 }
293
294 // Handle high-byte conversion (for compatibility with parseKeypress)
295 // If buffer has single byte > 127, convert to ESC + (byte - 128)
296 let str: string;
297 if (Buffer.isBuffer(data)) {
298 if (data.length === 1 && data[0]! > 127) {
299 const byte = data[0]! - 128;
300 str = `\x1b${String.fromCharCode(byte)}`;
301 } else {
302 str = data.toString();
303 }
304 } else {
305 str = data;
306 }
307
308 if (str.length === 0 && this.buffer.length === 0) {
309 this.emitDataSequence("");
310 return;
311 }
312
313 this.buffer += str;
314
315 if (this.pasteMode) {
316 this.pasteBuffer += this.buffer;
317 this.buffer = "";
318
319 const endIndex = this.pasteBuffer.indexOf(BRACKETED_PASTE_END);
320 if (endIndex !== -1) {
321 const pastedContent = this.pasteBuffer.slice(0, endIndex);
322 const remaining = this.pasteBuffer.slice(endIndex + BRACKETED_PASTE_END.length);
323
324 this.pasteMode = false;
325 this.pasteBuffer = "";
326 this.pendingKittyPrintableCodepoint = undefined;
327
328 this.emit("paste", pastedContent);
329
330 if (remaining.length > 0) {
331 this.process(remaining);
332 }
333 }
334 return;
335 }
336
337 const startIndex = this.buffer.indexOf(BRACKETED_PASTE_START);
338 if (startIndex !== -1) {
339 if (startIndex > 0) {
340 const beforePaste = this.buffer.slice(0, startIndex);
341 const result = extractCompleteSequences(beforePaste);
342 for (const sequence of result.sequences) {
343 this.emitDataSequence(sequence);
344 }

Callers

nothing calls this directly

Calls 5

emitDataSequenceMethod · 0.95
flushMethod · 0.95
extractCompleteSequencesFunction · 0.85
toStringMethod · 0.65
emitMethod · 0.45

Tested by

no test coverage detected