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
+25
View File
@@ -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();