Elffuss BraidHub

kikocis/continue public

406467d04db9 · 24.5 KiBRawPermalink
1/* eslint-disable max-lines */
2import { type AssistantConfig } from "@continuedev/sdk";
3import { Box, Text, useApp, useInput } from "ink";
4import React, { useCallback, useState } from "react";
5
6import { getAllSlashCommands } from "../commands/commands.js";
7import { useServices } from "../hooks/useService.js";
8import type { PermissionMode } from "../permissions/types.js";
9import type { FileIndexServiceState } from "../services/FileIndexService.js";
10import { SERVICE_NAMES, serviceContainer } from "../services/index.js";
11import { modeService } from "../services/ModeService.js";
12import { messageQueue } from "../stream/messageQueue.js";
13import { InputHistory } from "../util/inputHistory.js";
14
15import { FileSearchUI } from "./FileSearchUI.js";
16import { useClipboardMonitor } from "./hooks/useClipboardMonitor.js";
17import {
18 handleControlKeys,
19 updateTextBufferState,
20} from "./hooks/useUserInput.js";
21import { SlashCommandUI } from "./SlashCommandUI.js";
22import { TextBuffer } from "./TextBuffer.js";
23
24// Small presentational helpers to reduce cyclomatic complexity in UserInput
25const InterruptedBanner: React.FC<{ wasInterrupted: boolean }> = ({
26 wasInterrupted,
27}) => {
28 if (!wasInterrupted) return null;
29 return (
30 <Box paddingX={1} marginBottom={0}>
31 <Text color="yellow">Interrupted by user - Press enter to continue</Text>
32 </Box>
33 );
34};
35
36const SlashCommandsMaybe: React.FC<{
37 show: boolean;
38 inputMode: boolean;
39 hideNormalUI: boolean;
40 isRemoteMode: boolean;
41 assistant?: AssistantConfig;
42 filter: string;
43 selectedIndex: number;
44}> = ({
45 show,
46 inputMode,
47 hideNormalUI,
48 isRemoteMode,
49 assistant,
50 filter,
51 selectedIndex,
52}) => {
53 if (!show || !inputMode || hideNormalUI || !(isRemoteMode || assistant))
54 return null;
55 return (
56 <SlashCommandUI
57 assistant={assistant}
58 filter={filter}
59 selectedIndex={selectedIndex}
60 isRemoteMode={isRemoteMode}
61 />
62 );
63};
64
65const FileSearchMaybe: React.FC<{
66 show: boolean;
67 inputMode: boolean;
68 hideNormalUI: boolean;
69 isRemoteMode: boolean;
70 filter: string;
71 selectedIndex: number;
72 onSelect: (path: string) => void | Promise<void>;
73 onFilesUpdated: (files: Array<{ path: string; displayName: string }>) => void;
74}> = ({
75 show,
76 inputMode,
77 hideNormalUI,
78 isRemoteMode,
79 filter,
80 selectedIndex,
81 onSelect,
82 onFilesUpdated,
83}) => {
84 if (!show || !inputMode || hideNormalUI || isRemoteMode) return null;
85 return (
86 <FileSearchUI
87 filter={filter}
88 selectedIndex={selectedIndex}
89 onSelect={onSelect}
90 onFilesUpdated={onFilesUpdated}
91 />
92 );
93};
94
95interface UserInputProps {
96 onSubmit: (message: string, imageMap?: Map<string, Buffer>) => void;
97 isWaitingForResponse: boolean;
98 isCompacting?: boolean;
99 inputMode: boolean;
100 onInterrupt?: () => void;
101 assistant?: AssistantConfig;
102 wasInterrupted?: boolean;
103 onFileAttached?: (filePath: string, content: string) => void;
104 disabled?: boolean;
105 placeholder?: string;
106 hideNormalUI?: boolean;
107 isRemoteMode?: boolean;
108 onImageInClipboardChange?: (hasImage: boolean) => void;
109}
110
111const UserInput: React.FC<UserInputProps> = ({
112 onSubmit,
113 isWaitingForResponse,
114 isCompacting = false,
115 inputMode,
116 onInterrupt,
117 assistant,
118 wasInterrupted = false,
119 onFileAttached,
120 disabled = false,
121 placeholder,
122 hideNormalUI = false,
123 isRemoteMode = false,
124 onImageInClipboardChange,
125}) => {
126 const [textBuffer] = useState(() => new TextBuffer());
127 const [inputHistory] = useState(() => new InputHistory());
128
129 // Stable callback for TextBuffer state changes to prevent race conditions
130 const onStateChange = useCallback(() => {
131 setInputText(textBuffer.text);
132 setCursorPosition(textBuffer.cursor);
133 }, [textBuffer]);
134
135 // Set up callback for when TextBuffer state changes (e.g., rapid input finalized)
136 React.useEffect(() => {
137 textBuffer.setStateChangeCallback(onStateChange);
138
139 // Cleanup on unmount: clear any pending timers
140 return () => {
141 textBuffer.clear();
142 };
143 }, [textBuffer, onStateChange]);
144 const [inputText, setInputText] = useState("");
145 const [cursorPosition, setCursorPosition] = useState(0);
146 const [showSlashCommands, setShowSlashCommands] = useState(false);
147
148 // Clear input function for Ctrl+C
149 const clearInput = useCallback(() => {
150 textBuffer.clear();
151 setInputText("");
152 setCursorPosition(0);
153 setShowSlashCommands(false);
154 setShowFileSearch(false);
155 setShowBashMode(false);
156 inputHistory.resetNavigation();
157 }, [textBuffer]);
158
159 const [slashCommandFilter, setSlashCommandFilter] = useState("");
160 const [selectedCommandIndex, setSelectedCommandIndex] = useState(0);
161 const [showBashMode, setShowBashMode] = useState(false);
162 const [showFileSearch, setShowFileSearch] = useState(false);
163 const [fileSearchFilter, setFileSearchFilter] = useState("");
164 const [selectedFileIndex, setSelectedFileIndex] = useState(0);
165 const [currentFiles, setCurrentFiles] = useState<
166 Array<{ path: string; displayName: string }>
167 >([]);
168 const { exit } = useApp();
169
170 // Get file index service
171 const { services } = useServices<{
172 fileIndex: FileIndexServiceState;
173 }>(["fileIndex"]);
174
175 const getSlashCommands = () => {
176 if (assistant || isRemoteMode) {
177 return getAllSlashCommands(assistant || ({} as AssistantConfig), {
178 isRemoteMode,
179 });
180 }
181
182 // Fallback - basic commands without assistant
183 return [
184 { name: "help", description: "Show help message" },
185 { name: "clear", description: "Clear the chat history" },
186 { name: "exit", description: "Exit the chat" },
187 ];
188 };
189
190 // Cycle through permission modes
191 const cycleModes = async () => {
192 const modes: PermissionMode[] = ["normal", "plan", "auto"];
193 const currentMode = modeService.getCurrentMode();
194 const currentIndex = modes.indexOf(currentMode);
195 const nextIndex = (currentIndex + 1) % modes.length;
196 const nextMode = modes[nextIndex];
197
198 modeService.switchMode(nextMode);
199
200 // Update the service container with the new tool permissions state
201 // Since TOOL_PERMISSIONS was registered with registerValue(), we need to
202 // update its value directly rather than reloading from a factory
203 const updatedState = modeService.getToolPermissionService().getState();
204 serviceContainer.set(SERVICE_NAMES.TOOL_PERMISSIONS, updatedState);
205
206 // Show a brief indicator of the mode change
207 // This will be reflected in the ModeIndicator component
208 return nextMode;
209 };
210
211 // Update shell mode state based on input
212 const updateBashModeState = (text: string) => {
213 const trimmed = text.trimStart();
214 const isBash = trimmed.startsWith("!");
215 setShowBashMode(isBash);
216 if (isBash) {
217 // Disable other helpers while in shell mode
218 setShowSlashCommands(false);
219 setShowFileSearch(false);
220 }
221 };
222
223 // Update slash command UI state based on input
224 const updateSlashCommandState = (text: string, cursor: number) => {
225 // Only show slash commands if slash is the very first character
226 if (!text.trimStart().startsWith("/")) {
227 setShowSlashCommands(false);
228 return;
229 }
230
231 // When using slash commands, disable file search
232 setShowFileSearch(false);
233
234 const trimmedText = text.trimStart();
235 const beforeCursor = trimmedText.slice(
236 0,
237 cursor - (text.length - trimmedText.length),
238 );
239
240 // Only show if cursor is after the slash and before any whitespace
241 if (beforeCursor.length === 0 || !beforeCursor.startsWith("/")) {
242 setShowSlashCommands(false);
243 return;
244 }
245
246 // Get the complete slash command, not just the part before cursor
247 const afterSlash = trimmedText.slice(1).split(/[\s\n]/)[0];
248
249 // We're in a slash command context - check if it's a complete command
250 const allCommands = getSlashCommands();
251 const exactMatch = allCommands.find((cmd) => cmd.name === afterSlash);
252
253 // Hide selector if we have an exact match and there's a space after cursor
254 if (exactMatch) {
255 const restOfText = text.slice(cursor);
256 // Only hide if there's a space or newline immediately after cursor
257 const shouldHide =
258 restOfText.startsWith(" ") || restOfText.startsWith("\n");
259 if (shouldHide) {
260 setShowSlashCommands(false);
261 return;
262 }
263 }
264
265 // Check if there are any matching commands
266 const filteredCommands = allCommands.filter((cmd) =>
267 cmd.name.toLowerCase().includes(afterSlash.toLowerCase()),
268 );
269
270 // If no commands match, hide the dropdown to allow normal Enter behavior
271 if (filteredCommands.length === 0) {
272 setShowSlashCommands(false);
273 return;
274 }
275
276 // Show selector for partial matches
277 setShowSlashCommands(true);
278 setSlashCommandFilter(afterSlash);
279 setSelectedCommandIndex(0);
280 setShowFileSearch(false);
281 };
282
283 // Update file search UI state based on input
284 const updateFileSearchState = (text: string, cursor: number) => {
285 // Don't show file search in remote mode
286 if (isRemoteMode) {
287 setShowFileSearch(false);
288 return;
289 }
290
291 // Disable file search if we're in shell mode or slash command mode
292 const trimmed = text.trimStart();
293 if (trimmed.startsWith("!") || trimmed.startsWith("/")) {
294 setShowFileSearch(false);
295 return;
296 }
297
298 // Check if we're in a file search context
299 const beforeCursor = text.slice(0, cursor);
300 const lastAtIndex = beforeCursor.lastIndexOf("@");
301
302 if (lastAtIndex === -1) {
303 setShowFileSearch(false);
304 } else {
305 // Check if there's any whitespace between the last @ and cursor
306 const afterAt = beforeCursor.slice(lastAtIndex + 1);
307
308 if (afterAt.includes(" ") || afterAt.includes("\n")) {
309 setShowFileSearch(false);
310 } else {
311 // We're in a file search context - check if there are matching files
312 const fileIndexService = services.fileIndex;
313 if (fileIndexService) {
314 const filteredFiles = fileIndexService.files.filter((file) => {
315 if (afterAt.length === 0) {
316 return true;
317 }
318 const lowerFilter = afterAt.toLowerCase();
319 return (
320 file.displayName.toLowerCase().includes(lowerFilter) ||
321 file.path.toLowerCase().includes(lowerFilter)
322 );
323 });
324
325 // If no files match, hide the dropdown to allow normal Enter behavior
326 if (filteredFiles.length === 0 && afterAt.length > 0) {
327 setShowFileSearch(false);
328 return;
329 }
330 }
331
332 setShowFileSearch(true);
333 setFileSearchFilter(afterAt);
334 setSelectedFileIndex(0);
335 setShowSlashCommands(false);
336 setShowBashMode(false);
337 }
338 }
339 };
340
341 // Get filtered commands for navigation - using the same sorting logic as SlashCommandUI
342 const getFilteredCommands = () => {
343 const allCommands = getSlashCommands();
344 return allCommands
345 .filter((cmd) =>
346 cmd.name.toLowerCase().includes(slashCommandFilter.toLowerCase()),
347 )
348 .sort((a, b) => {
349 const aStartsWith = a.name
350 .toLowerCase()
351 .startsWith(slashCommandFilter.toLowerCase());
352 const bStartsWith = b.name
353 .toLowerCase()
354 .startsWith(slashCommandFilter.toLowerCase());
355
356 if (aStartsWith && !bStartsWith) return -1;
357 if (!aStartsWith && bStartsWith) return 1;
358
359 return a.name.localeCompare(b.name);
360 });
361 };
362
363 // Handle slash command selection
364 const selectSlashCommand = (commandName: string) => {
365 const beforeCursor = inputText.slice(0, cursorPosition);
366 const lastSlashIndex = beforeCursor.lastIndexOf("/");
367
368 if (lastSlashIndex !== -1) {
369 const beforeSlash = inputText.slice(0, lastSlashIndex);
370 const afterCursor = inputText.slice(cursorPosition);
371
372 // Replace the partial command with the full command
373 const newText = beforeSlash + "/" + commandName + " " + afterCursor;
374 const newCursorPos = lastSlashIndex + 1 + commandName.length + 1;
375
376 textBuffer.setText(newText);
377 textBuffer.setCursor(newCursorPos);
378 setInputText(newText);
379 setCursorPosition(newCursorPos);
380 setShowSlashCommands(false);
381 setShowBashMode(false);
382 }
383 };
384
385 // Handle file selection
386 const selectFile = async (filePath: string) => {
387 const beforeCursor = inputText.slice(0, cursorPosition);
388 const lastAtIndex = beforeCursor.lastIndexOf("@");
389
390 if (lastAtIndex !== -1) {
391 const beforeAt = inputText.slice(0, lastAtIndex);
392 const afterCursor = inputText.slice(cursorPosition);
393
394 // Replace the partial file reference with the full file path
395 const newText = beforeAt + "@" + filePath + " " + afterCursor;
396 const newCursorPos = lastAtIndex + 1 + filePath.length + 1;
397
398 textBuffer.setText(newText);
399 textBuffer.setCursor(newCursorPos);
400 setInputText(newText);
401 setCursorPosition(newCursorPos);
402 setShowFileSearch(false);
403
404 // Read the file content and notify parent component
405 if (onFileAttached) {
406 try {
407 const fs = await import("fs/promises");
408 const path = await import("path");
409 const absolutePath = path.resolve(filePath);
410 const content = await fs.readFile(absolutePath, "utf-8");
411 onFileAttached(absolutePath, content);
412 } catch (error) {
413 console.error(`Error reading file ${filePath}:`, error);
414 }
415 }
416 }
417 };
418
419 const handleSlashCommandNavigation = (key: any): boolean => {
420 const filteredCommands = getFilteredCommands();
421
422 if (key.upArrow) {
423 setSelectedCommandIndex((prev) =>
424 prev > 0 ? prev - 1 : filteredCommands.length - 1,
425 );
426 return true;
427 }
428
429 if (key.downArrow) {
430 setSelectedCommandIndex((prev) =>
431 prev < filteredCommands.length - 1 ? prev + 1 : 0,
432 );
433 return true;
434 }
435
436 if ((key.return && !key.shift) || key.tab) {
437 if (filteredCommands.length > 0) {
438 selectSlashCommand(filteredCommands[selectedCommandIndex].name);
439 }
440 return true;
441 }
442
443 return false;
444 };
445
446 const handleFileSearchNavigation = (key: any): boolean => {
447 if (key.upArrow) {
448 setSelectedFileIndex((prev) =>
449 prev > 0 ? prev - 1 : Math.max(0, Math.min(currentFiles.length - 1, 9)),
450 );
451 return true;
452 }
453
454 if (key.downArrow) {
455 setSelectedFileIndex((prev) =>
456 prev < Math.min(currentFiles.length - 1, 9) ? prev + 1 : 0,
457 );
458 return true;
459 }
460
461 if ((key.return && !key.shift) || key.tab) {
462 if (currentFiles.length > 0 && selectedFileIndex < currentFiles.length) {
463 selectFile(currentFiles[selectedFileIndex].path);
464 }
465 return true;
466 }
467
468 return false;
469 };
470
471 const handleHistoryNavigation = (key: any): boolean => {
472 if (!showSlashCommands && !showFileSearch) {
473 if (key.upArrow) {
474 const historyEntry = inputHistory.navigateUp(inputText);
475 if (historyEntry !== null) {
476 textBuffer.setText(historyEntry);
477 textBuffer.setCursor(historyEntry.length);
478 setInputText(historyEntry);
479 setCursorPosition(historyEntry.length);
480 }
481 return true;
482 }
483
484 if (key.downArrow) {
485 const historyEntry = inputHistory.navigateDown();
486 if (historyEntry !== null) {
487 textBuffer.setText(historyEntry);
488 textBuffer.setCursor(historyEntry.length);
489 setInputText(historyEntry);
490 setCursorPosition(historyEntry.length);
491 }
492 return true;
493 }
494 }
495 return false;
496 };
497
498 const handleEnterKey = (key: any): boolean => {
499 if (key.return && !key.shift) {
500 // Check for backslash continuation
501 const beforeCursor = textBuffer.text.slice(0, cursorPosition);
502 const trimmedBeforeCursor = beforeCursor.trimEnd();
503
504 if (trimmedBeforeCursor.endsWith("\\")) {
505 // Handle backslash continuation: remove the trailing "\" and add newline
506 const beforeBackslash = trimmedBeforeCursor.slice(0, -1);
507 const afterCursor = textBuffer.text.slice(cursorPosition);
508 const newText = beforeBackslash + "\n" + afterCursor;
509 const newCursorPos = beforeBackslash.length + 1;
510
511 textBuffer.setText(newText);
512 textBuffer.setCursor(newCursorPos);
513 setInputText(newText);
514 setCursorPosition(newCursorPos);
515 updateSlashCommandState(newText, newCursorPos);
516 updateFileSearchState(newText, newCursorPos);
517 return true;
518 }
519
520 // Normal Enter behavior - submit if there's content
521 if (textBuffer.text.trim() || wasInterrupted) {
522 // Get images before expanding paste blocks
523 const imageMap = textBuffer.getAllImages();
524
525 // Expand all paste blocks before submitting
526 textBuffer.expandAllPasteBlocks();
527 const submittedText = textBuffer.text.trim();
528
529 if (isWaitingForResponse || isCompacting) {
530 // Process message later when LLM has responded or compaction is complete
531 void messageQueue.enqueueMessage(
532 submittedText,
533 imageMap,
534 inputHistory,
535 );
536 } else {
537 // Submit with images
538 inputHistory.addEntry(submittedText);
539 onSubmit(submittedText, imageMap);
540 }
541
542 textBuffer.clear();
543 setInputText("");
544 setCursorPosition(0);
545 setShowSlashCommands(false);
546 setShowBashMode(false);
547 }
548 return true;
549 }
550 return false;
551 };
552
553 const handleNewLine = (input: string, key: any): boolean => {
554 if (input === "\r" || input === "\\\r") {
555 const handled = textBuffer.handleInput("\n", key);
556 if (handled) {
557 const newText = textBuffer.text;
558 const newCursor = textBuffer.cursor;
559 setInputText(newText);
560 setCursorPosition(newCursor);
561 updateSlashCommandState(newText, newCursor);
562 updateFileSearchState(newText, newCursor);
563 }
564 return true;
565 }
566 return false;
567 };
568
569 const handleEscapeKey = (key: any): boolean => {
570 if (!key.escape) return false;
571
572 // If only "!" is present, clear shell mode
573 if (inputMode && showBashMode && inputText.trim() === "!") {
574 textBuffer.clear();
575 setInputText("");
576 setCursorPosition(0);
577 setShowBashMode(false);
578 return true;
579 }
580
581 // Handle escape key to interrupt compaction (higher priority)
582 if (isCompacting && onInterrupt) {
583 onInterrupt();
584 return true;
585 }
586
587 // Handle escape key to interrupt streaming
588 if (isWaitingForResponse && onInterrupt) {
589 onInterrupt();
590 return true;
591 }
592
593 // Handle escape key to close slash command UI
594 if (showSlashCommands && inputMode) {
595 setShowSlashCommands(false);
596 return true;
597 }
598
599 // Handle escape key to close file search UI
600 if (showFileSearch && inputMode) {
601 setShowFileSearch(false);
602 return true;
603 }
604
605 return false;
606 };
607
608 // Handle text buffer updates for async operations like image pasting
609 const handleTextBufferUpdate = () => {
610 const newText = textBuffer.text;
611 const newCursor = textBuffer.cursor;
612 setInputText(newText);
613 setCursorPosition(newCursor);
614 updateSlashCommandState(newText, newCursor);
615 updateFileSearchState(newText, newCursor);
616 updateBashModeState(newText);
617 inputHistory.resetNavigation();
618 };
619
620 // State for showing image paste hint
621 const [_hasImageInClipboard, _setHasImageInClipboard] = useState(false);
622
623 // Monitor clipboard for images and show helpful hints
624 const { checkNow: _checkClipboardNow } = useClipboardMonitor({
625 onImageStatusChange: (hasImage) => {
626 _setHasImageInClipboard(hasImage);
627 // Also notify parent component
628 if (onImageInClipboardChange) {
629 onImageInClipboardChange(hasImage);
630 }
631 },
632 enabled: !disabled && inputMode,
633 pollInterval: 2000,
634 });
635
636 useInput((input, key) => {
637 // Don't handle any input when disabled
638 if (disabled) {
639 return;
640 }
641
642 // Handle control keys
643 if (
644 handleControlKeys({
645 input,
646 key,
647 exit,
648 showSlashCommands,
649 showFileSearch,
650 cycleModes,
651 clearInput,
652 textBuffer,
653 onTextBufferUpdate: handleTextBufferUpdate,
654 })
655 ) {
656 return;
657 }
658
659 // Handle escape key variations
660 if (handleEscapeKey(key)) {
661 return;
662 }
663
664 // Handle slash command navigation
665 if (showSlashCommands) {
666 if (handleSlashCommandNavigation(key)) {
667 return;
668 }
669 }
670
671 // Handle file search navigation
672 if (showFileSearch) {
673 if (handleFileSearchNavigation(key)) {
674 return;
675 }
676 }
677
678 // Handle input history navigation
679 if (handleHistoryNavigation(key)) {
680 return;
681 }
682
683 // Handle Enter key
684 if (handleEnterKey(key)) {
685 return;
686 }
687
688 // Handle Shift+Enter (new line)
689 if (handleNewLine(input, key)) {
690 return;
691 }
692
693 // Let TextBuffer handle the input
694 const handled = textBuffer.handleInput(input, key);
695
696 // Update React state to trigger re-render
697 updateTextBufferState({
698 handled,
699 textBuffer,
700 setInputText,
701 setCursorPosition,
702 updateSlashCommandState,
703 updateFileSearchState,
704 updateBashModeState,
705 inputHistory,
706 });
707 });
708
709 const renderInputText = () => {
710 const placeholderText = isRemoteMode
711 ? "Ask anything, / for slash commands, ! for shell mode"
712 : placeholder ||
713 "Ask anything, @ for context, / for slash commands, ! for shell mode";
714 if (inputText.length === 0) {
715 return (
716 <>
717 {(inputMode || isWaitingForResponse) && (
718 <Text italic color="gray">
719 ▋{placeholderText}
720 </Text>
721 )}
722 {!inputMode && !isWaitingForResponse && (
723 <Text italic color="gray">
724 {placeholderText}
725 </Text>
726 )}
727 </>
728 );
729 }
730
731 if (inputMode || isWaitingForResponse) {
732 // Handle multi-line text with cursor
733 const lines = inputText.split("\n");
734 let charCount = 0;
735 let cursorLine = 0;
736 let cursorCol = 0;
737
738 // Find which line and column the cursor is on
739 for (let i = 0; i < lines.length; i++) {
740 if (cursorPosition <= charCount + lines[i].length) {
741 cursorLine = i;
742 cursorCol = cursorPosition - charCount;
743 break;
744 }
745 charCount += lines[i].length + 1; // +1 for the newline character
746 }
747
748 // Handle cursor at the very end
749 if (cursorPosition >= inputText.length) {
750 cursorLine = lines.length - 1;
751 cursorCol = lines[cursorLine].length;
752 }
753
754 return (
755 <Box flexDirection="column">
756 {lines.map((line, lineIndex) => {
757 if (lineIndex === cursorLine) {
758 // Line with cursor
759 const beforeCursor = line.slice(0, cursorCol);
760 const atCursor = line.slice(cursorCol, cursorCol + 1);
761 const afterCursor = line.slice(cursorCol + 1);
762
763 return (
764 <Text key={lineIndex}>
765 {beforeCursor}
766 <Text inverse>{atCursor || " "}</Text>
767 {afterCursor}
768 </Text>
769 );
770 } else {
771 // Regular line - ensure empty lines still render
772 return <Text key={lineIndex}>{line || " "}</Text>;
773 }
774 })}
775 </Box>
776 );
777 } else {
778 // Not in input mode, just display the text
779 return (
780 <Box flexDirection="column">
781 {inputText.split("\n").map((line, index) => (
782 <Text key={index}>{line || " "}</Text>
783 ))}
784 </Box>
785 );
786 }
787 };
788
789 // Don't render anything when disabled
790 if (disabled) {
791 return null;
792 }
793
794 return (
795 <Box flexDirection="column">
796 <InterruptedBanner wasInterrupted={!!wasInterrupted} />
797
798 {/* Input box */}
799 <Box
800 borderStyle="round"
801 borderTop={true}
802 paddingX={1}
803 borderColor={showBashMode ? "yellow" : isRemoteMode ? "cyan" : "gray"}
804 >
805 <Text
806 color={showBashMode ? "yellow" : isRemoteMode ? "cyan" : "blue"}
807 bold
808 >
809 {showBashMode ? "$ " : isRemoteMode ? "◉ " : "● "}
810 </Text>
811 {renderInputText()}
812 </Box>
813
814 <SlashCommandsMaybe
815 show={showSlashCommands}
816 inputMode={inputMode}
817 hideNormalUI={!!hideNormalUI}
818 isRemoteMode={!!isRemoteMode}
819 assistant={assistant}
820 filter={slashCommandFilter}
821 selectedIndex={selectedCommandIndex}
822 />
823
824 <FileSearchMaybe
825 show={showFileSearch}
826 inputMode={inputMode}
827 hideNormalUI={!!hideNormalUI}
828 isRemoteMode={!!isRemoteMode}
829 filter={fileSearchFilter}
830 selectedIndex={selectedFileIndex}
831 onSelect={selectFile}
832 onFilesUpdated={setCurrentFiles}
833 />
834 </Box>
835 );
836};
837
838export { UserInput };