feat(tui): single ctrl+c clears input, double ctrl+c exits
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user