diff --git a/src/components/ConsoleInput.tsx b/src/components/ConsoleInput.tsx index c7ad430..a64bf5d 100644 --- a/src/components/ConsoleInput.tsx +++ b/src/components/ConsoleInput.tsx @@ -25,7 +25,29 @@ export default function ConsoleInput({ onSend, disabled = false }: ConsoleInputP setHistoryIndex(-1) }, [input, disabled, onSend, history]) + const sendControlChar = useCallback((char: 'C' | 'D') => { + if (disabled) return + + // Send control character (Ctrl-C = 0x03, Ctrl-D = 0x04) + const code = char === 'C' ? 3 : 4 + const controlChar = String.fromCharCode(code) + onSend(controlChar) + }, [disabled, onSend]) + const handleKeyDown = useCallback((e: KeyboardEvent) => { + // Handle Ctrl-C and Ctrl-D + if (e.ctrlKey || e.metaKey) { + if (e.key === 'c' || e.key === 'C') { + e.preventDefault() + sendControlChar('C') + return + } else if (e.key === 'd' || e.key === 'D') { + e.preventDefault() + sendControlChar('D') + return + } + } + if (e.key === 'Enter') { e.preventDefault() handleSend() @@ -51,7 +73,7 @@ export default function ConsoleInput({ onSend, disabled = false }: ConsoleInputP } } } - }, [handleSend, history, historyIndex]) + }, [handleSend, history, historyIndex, sendControlChar]) return (
@@ -61,10 +83,26 @@ export default function ConsoleInput({ onSend, disabled = false }: ConsoleInputP value={input} onChange={(e) => setInput(e.target.value)} onKeyDown={handleKeyDown} - placeholder={disabled ? "Not connected" : "Type command and press Enter..."} + placeholder={disabled ? "Not connected" : "Type command and press Enter (Ctrl-C, Ctrl-D supported)..."} disabled={disabled} className="flex-1 px-3 py-2 text-sm border border-gray-300 dark:border-neutral-700 rounded-md bg-white dark:bg-neutral-900 text-gray-900 dark:text-neutral-100 placeholder-gray-400 dark:placeholder-neutral-500 focus:outline-none focus:ring-2 focus:ring-blue-500 dark:focus:ring-blue-400 disabled:opacity-50 disabled:cursor-not-allowed" /> + +