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

Method drainInput

packages/pi-tui/src/terminal.ts:368–404  ·  view source on GitHub ↗
(maxMs = 1000, idleMs = 50)

Source from the content-addressed store, hash-verified

366 }
367
368 async drainInput(maxMs = 1000, idleMs = 50): Promise<void> {
369 const shouldDisableKittyProtocol = this.keyboardProtocolPushed || this._kittyProtocolActive;
370 this.clearKeyboardProtocolNegotiationBuffer();
371 if (shouldDisableKittyProtocol) {
372 // Disable Kitty keyboard protocol first so any late key releases
373 // do not generate new Kitty escape sequences.
374 process.stdout.write("\x1b[<u");
375 this.keyboardProtocolPushed = false;
376 this._kittyProtocolActive = false;
377 setKittyProtocolActive(false);
378 }
379 this.disableModifyOtherKeys();
380
381 const previousHandler = this.inputHandler;
382 this.inputHandler = undefined;
383
384 let lastDataTime = Date.now();
385 const onData = () => {
386 lastDataTime = Date.now();
387 };
388
389 process.stdin.on("data", onData);
390 const endTime = Date.now() + maxMs;
391
392 try {
393 while (true) {
394 const now = Date.now();
395 const timeLeft = endTime - now;
396 if (timeLeft <= 0) break;
397 if (now - lastDataTime >= idleMs) break;
398 await new Promise((resolve) => setTimeout(resolve, Math.min(idleMs, timeLeft)));
399 }
400 } finally {
401 process.stdin.removeListener("data", onData);
402 this.inputHandler = previousHandler;
403 }
404 }
405
406 stop(): void {
407 if (this.clearProgressInterval()) {

Callers

nothing calls this directly

Calls 6

setKittyProtocolActiveFunction · 0.90
writeMethod · 0.65
nowMethod · 0.65
onMethod · 0.65

Tested by

no test coverage detected