mirror of
https://github.com/Ark0N/Codeman.git
synced 2026-10-02 13:39:41 +02:00
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:
+19
-2
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user