From 3b3637009d16db8198e065c0f6bbd96159c4624f Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Fri, 26 Sep 2025 18:01:40 -0500 Subject: [PATCH] Fix focus in TUI --- src/components/Terminal.tsx | 75 ++++++++++++++++++++++++------------- 1 file changed, 50 insertions(+), 25 deletions(-) diff --git a/src/components/Terminal.tsx b/src/components/Terminal.tsx index 3f573701..7f26d6e9 100644 --- a/src/components/Terminal.tsx +++ b/src/components/Terminal.tsx @@ -48,12 +48,12 @@ export function Terminal({ projectId, onClose, className }: TerminalProps) { }]); }, [projectId, fs, git]); - // Auto-scroll to bottom when new lines are added + // Auto-scroll to bottom when new lines are added or execution state changes useEffect(() => { if (scrollRef.current) { scrollRef.current.scrollTop = scrollRef.current.scrollHeight; } - }, [lines]); + }, [lines, isExecuting]); // Focus input when component mounts useEffect(() => { @@ -62,6 +62,13 @@ export function Terminal({ projectId, onClose, className }: TerminalProps) { } }, []); + // Refocus input after command execution + useEffect(() => { + if (!isExecuting && inputRef.current) { + inputRef.current.focus(); + } + }, [isExecuting]); + const addLine = useCallback((type: TerminalLine['type'], content: string) => { const newLine: TerminalLine = { id: Date.now().toString() + Math.random(), @@ -164,6 +171,13 @@ export function Terminal({ projectId, onClose, className }: TerminalProps) { return `${projectId}:${relativePath}$`; }; + // Focus input when clicking anywhere in the terminal + const handleTerminalClick = useCallback(() => { + if (inputRef.current) { + inputRef.current.focus(); + } + }, []); + return (
{/* Terminal Header */} @@ -199,7 +213,7 @@ export function Terminal({ projectId, onClose, className }: TerminalProps) {
{/* Terminal Content */} -
+
{lines.map((line) => ( @@ -218,7 +232,10 @@ export function Terminal({ projectId, onClose, className }: TerminalProps) {
)} + + {/* Current Command Input - inline with content */} + {!isExecuting && ( +
+ + {getPrompt()} + +
+ setCurrentInput(e.target.value)} + onKeyDown={handleKeyDown} + disabled={isExecuting} + className="w-full bg-transparent border-none outline-none text-green-400 font-mono text-xs placeholder-gray-500 caret-green-400" + placeholder="" + autoComplete="off" + spellCheck="false" + /> + {/* Blinking cursor when input is empty */} + {!currentInput && ( + + _ + + )} +
+
+ )}
- - {/* Command Input */} -
-
- - {getPrompt()} - - setCurrentInput(e.target.value)} - onKeyDown={handleKeyDown} - disabled={isExecuting} - className="flex-1 bg-transparent border-none outline-none text-green-400 font-mono text-xs placeholder-gray-500" - placeholder="Enter command..." - autoComplete="off" - spellCheck="false" - /> -
-
);