Skip to content

Commit f5f8ad5

Browse files
committed
Handle SIGINT globally with visible exit message
1 parent 84f6230 commit f5f8ad5

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
@@ -29,6 +29,19 @@ import { setOscDetectedTheme } from './utils/theme-system'
2929

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

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

3447
function loadPackageVersion(): string {

0 commit comments

Comments
 (0)