Skip to content

Commit 38d013f

Browse files
committed
Handle SIGINT globally with visible exit message
1 parent 6619257 commit 38d013f

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

cli/src/index.tsx

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,19 @@ import { setOscDetectedTheme } from './utils/theme-system'
2828

2929
import type { FileTreeNode } from '@codebuff/common/util/file'
3030

31+
// Ensure SIGINT always produces a clean, visible exit even if the UI misses the key event.
32+
let globalSigintHandled = false
33+
process.on('SIGINT', () => {
34+
if (globalSigintHandled) return
35+
globalSigintHandled = true
36+
try {
37+
process.stdout.write('\nGoodbye! Exiting (SIGINT)...\nexit\n')
38+
} catch {
39+
// Ignore write errors during shutdown
40+
}
41+
process.exit(0)
42+
})
43+
3144
const require = createRequire(import.meta.url)
3245

3346
function loadPackageVersion(): string {

0 commit comments

Comments
 (0)