feat(tui): add graceful exit handling with terminal restoration

- Handle SIGINT/SIGTERM signals properly
- Unmount Ink app before exit
- Restore cursor visibility and clear screen on exit
- Use try/finally to ensure cleanup runs

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
arkon
2026-01-21 06:54:32 +01:00
co-authored by Claude Opus 4.5
parent d8803e3318
commit d87711279f
+19 -2
View File
@@ -65,7 +65,24 @@ export async function startTUI(): Promise<void> {
// Clear the terminal for full-screen experience
process.stdout.write('\x1b[2J\x1b[H');
const { waitUntilExit } = render(<App />);
const { waitUntilExit, unmount } = render(<App />);
await waitUntilExit();
// Handle graceful exit on SIGINT/SIGTERM
const cleanup = () => {
unmount();
// Restore terminal state
process.stdout.write('\x1b[?25h'); // Show cursor
process.stdout.write('\x1b[2J\x1b[H'); // Clear screen
};
process.on('SIGINT', cleanup);
process.on('SIGTERM', cleanup);
try {
await waitUntilExit();
} finally {
process.off('SIGINT', cleanup);
process.off('SIGTERM', cleanup);
cleanup();
}
}