feat(tui): single ctrl+c clears input, double ctrl+c exits
This commit is contained in:
@@ -238,7 +238,30 @@ export function registerTuiCommand(program: Command): void {
|
||||
return cleanupPromise;
|
||||
};
|
||||
|
||||
let activeCtrlCHandler: (() => boolean) | null = null;
|
||||
let lastCtrlCAtMs = 0;
|
||||
const ctrlCExitWindowMs = 1_500;
|
||||
|
||||
const signalHandler = (signal: NodeJS.Signals) => {
|
||||
if (signal === 'SIGINT' && activeCtrlCHandler) {
|
||||
// Minimal TUI owns Ctrl+C behavior via readline SIGINT handling.
|
||||
return;
|
||||
}
|
||||
|
||||
if (signal === 'SIGINT') {
|
||||
const now = Date.now();
|
||||
const isDoublePress = lastCtrlCAtMs > 0 && (now - lastCtrlCAtMs) <= ctrlCExitWindowMs;
|
||||
lastCtrlCAtMs = now;
|
||||
|
||||
if (!isDoublePress) {
|
||||
if (activeCtrlCHandler && !activeCtrlCHandler()) {
|
||||
return;
|
||||
}
|
||||
console.log('\nPress Ctrl+C again to quit (or use /quit).');
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
console.log(`\nReceived ${signal}; shutting down TUI...`);
|
||||
void cleanup()
|
||||
.then(() => process.exit(0))
|
||||
@@ -313,8 +336,10 @@ export function registerTuiCommand(program: Command): void {
|
||||
tui.stop(true);
|
||||
},
|
||||
});
|
||||
activeCtrlCHandler = () => tui.handleCtrlCPress();
|
||||
|
||||
await tui.start();
|
||||
activeCtrlCHandler = null;
|
||||
|
||||
if (switchingToFullscreen) {
|
||||
console.clear();
|
||||
|
||||
Reference in New Issue
Block a user