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

Class Input

packages/pi-tui/src/components/input.ts:19–447  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

17 * Input component - single-line text input with horizontal scrolling
18 */
19export class Input implements Component, Focusable {
20 private value: string = "";
21 private cursor: number = 0; // Cursor position in the value
22 public onSubmit?: (value: string) => void;
23 public onEscape?: () => void;
24
25 /** Focusable interface - set by TUI when focus changes */
26 focused: boolean = false;
27
28 // Bracketed paste mode buffering
29 private pasteBuffer: string = "";
30 private isInPaste: boolean = false;
31
32 // Kill ring for Emacs-style kill/yank operations
33 private killRing = new KillRing();
34 private lastAction: "kill" | "yank" | "type-word" | null = null;
35
36 // Undo support
37 private undoStack = new UndoStack<InputState>();
38
39 getValue(): string {
40 return this.value;
41 }
42
43 setValue(value: string): void {
44 this.value = value;
45 this.cursor = Math.min(this.cursor, value.length);
46 }
47
48 handleInput(data: string): void {
49 // Handle bracketed paste mode
50 // Start of paste: \x1b[200~
51 // End of paste: \x1b[201~
52
53 // Check if we're starting a bracketed paste
54 if (data.includes("\x1b[200~")) {
55 this.isInPaste = true;
56 this.pasteBuffer = "";
57 data = data.replace("\x1b[200~", "");
58 }
59
60 // If we're in a paste, buffer the data
61 if (this.isInPaste) {
62 // Check if this chunk contains the end marker
63 this.pasteBuffer += data;
64
65 const endIndex = this.pasteBuffer.indexOf("\x1b[201~");
66 if (endIndex !== -1) {
67 // Extract the pasted content
68 const pasteContent = this.pasteBuffer.substring(0, endIndex);
69
70 // Process the complete paste
71 this.handlePaste(pasteContent);
72
73 // Reset paste state
74 this.isInPaste = false;
75
76 // Handle any remaining input after the paste marker

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected