feat(tui): single ctrl+c clears input, double ctrl+c exits

This commit is contained in:
William Valentin
2026-02-18 11:38:21 -08:00
parent 21232748b9
commit 67d235ebf5
6 changed files with 141 additions and 1 deletions
+17
View File
@@ -77,6 +77,7 @@ export function App({
onTransfer,
onExit,
}: AppProps): React.ReactElement {
const ctrlCExitWindowMs = 1_500;
const { exit } = useApp();
const [input, setInput] = useState('');
const [messages, setMessages] = useState<Message[]>(session.getHistory());
@@ -91,6 +92,7 @@ export function App({
});
const abortRef = useRef(false);
const lastCtrlCAtRef = useRef(0);
const toolLinesRef = useRef<string[]>([]);
const confirmResolveRef = useRef<((result: HookResult) => void) | null>(null);
@@ -177,6 +179,21 @@ export function App({
return;
}
if (key.ctrl && inputChar.toLowerCase() === 'c') {
const now = Date.now();
const shouldExit = lastCtrlCAtRef.current > 0 && (now - lastCtrlCAtRef.current) <= ctrlCExitWindowMs;
lastCtrlCAtRef.current = now;
if (shouldExit) {
onExit?.();
exit();
return;
}
if (input.length > 0) {
setInput('');
}
return;
}
// Tab completion for slash commands
if (key.tab && !isStreaming) {
const completions = getCommandCompletions(input);