feat(cli): support single Ctrl+C to cancel streaming, preserving double Ctrl+C to exit (#5838)
This commit is contained in:
parent
f9efb2e24f
commit
2d1a6af890
|
@ -545,6 +545,7 @@ const App = ({ config, settings, startupWarnings = [], version }: AppProps) => {
|
||||||
initError,
|
initError,
|
||||||
pendingHistoryItems: pendingGeminiHistoryItems,
|
pendingHistoryItems: pendingGeminiHistoryItems,
|
||||||
thought,
|
thought,
|
||||||
|
cancelOngoingRequest,
|
||||||
} = useGeminiStream(
|
} = useGeminiStream(
|
||||||
config.getGeminiClient(),
|
config.getGeminiClient(),
|
||||||
history,
|
history,
|
||||||
|
@ -655,6 +656,9 @@ const App = ({ config, settings, startupWarnings = [], version }: AppProps) => {
|
||||||
if (isAuthenticating) {
|
if (isAuthenticating) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (!ctrlCPressedOnce) {
|
||||||
|
cancelOngoingRequest?.();
|
||||||
|
}
|
||||||
handleExit(ctrlCPressedOnce, setCtrlCPressedOnce, ctrlCTimerRef);
|
handleExit(ctrlCPressedOnce, setCtrlCPressedOnce, ctrlCTimerRef);
|
||||||
} else if (keyMatchers[Command.EXIT](key)) {
|
} else if (keyMatchers[Command.EXIT](key)) {
|
||||||
if (buffer.text.length > 0) {
|
if (buffer.text.length > 0) {
|
||||||
|
@ -686,6 +690,7 @@ const App = ({ config, settings, startupWarnings = [], version }: AppProps) => {
|
||||||
ctrlDTimerRef,
|
ctrlDTimerRef,
|
||||||
handleSlashCommand,
|
handleSlashCommand,
|
||||||
isAuthenticating,
|
isAuthenticating,
|
||||||
|
cancelOngoingRequest,
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
@ -56,9 +56,9 @@ export const ToolConfirmationMessage: React.FC<
|
||||||
onConfirm(outcome);
|
onConfirm(outcome);
|
||||||
};
|
};
|
||||||
|
|
||||||
useInput((_, key) => {
|
useInput((input, key) => {
|
||||||
if (!isFocused) return;
|
if (!isFocused) return;
|
||||||
if (key.escape) {
|
if (key.escape || (key.ctrl && (input === 'c' || input === 'C'))) {
|
||||||
handleConfirm(ToolConfirmationOutcome.Cancel);
|
handleConfirm(ToolConfirmationOutcome.Cancel);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -183,8 +183,10 @@ export const useGeminiStream = (
|
||||||
return StreamingState.Idle;
|
return StreamingState.Idle;
|
||||||
}, [isResponding, toolCalls]);
|
}, [isResponding, toolCalls]);
|
||||||
|
|
||||||
useInput((_input, key) => {
|
const cancelOngoingRequest = useCallback(() => {
|
||||||
if (streamingState === StreamingState.Responding && key.escape) {
|
if (streamingState !== StreamingState.Responding) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (turnCancelledRef.current) {
|
if (turnCancelledRef.current) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -203,6 +205,17 @@ export const useGeminiStream = (
|
||||||
setPendingHistoryItem(null);
|
setPendingHistoryItem(null);
|
||||||
onCancelSubmit();
|
onCancelSubmit();
|
||||||
setIsResponding(false);
|
setIsResponding(false);
|
||||||
|
}, [
|
||||||
|
streamingState,
|
||||||
|
addItem,
|
||||||
|
setPendingHistoryItem,
|
||||||
|
onCancelSubmit,
|
||||||
|
pendingHistoryItemRef,
|
||||||
|
]);
|
||||||
|
|
||||||
|
useInput((_input, key) => {
|
||||||
|
if (key.escape) {
|
||||||
|
cancelOngoingRequest();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -954,5 +967,6 @@ export const useGeminiStream = (
|
||||||
initError,
|
initError,
|
||||||
pendingHistoryItems,
|
pendingHistoryItems,
|
||||||
thought,
|
thought,
|
||||||
|
cancelOngoingRequest,
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue