Elffuss BraidHub

kikocis/continue public

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