Exit only once the renderer has restored the terminal

OpenTUI 0.8 restores the terminal after destroy() returns; renderer.closed
says when it is done.
This commit is contained in:
Callum Alpass committed 2026-11-03 02:09:44 +11:00
1 parent ba157ccab7
commit 1399112379
2 files changed
+3 -2

No files matched your search

+2 -1
View File
@@ -149,8 +149,9 @@ async function runUi(attachNeedle?: string) {
const renderer = await createCliRenderer({ exitOnCtrlC: false, useMouse: true, useKittyKeyboard: {} }); const renderer = await createCliRenderer({ exitOnCtrlC: false, useMouse: true, useKittyKeyboard: {} });
// OpenTUI answers SIGHUP and SIGTERM by tearing the screen down without exiting, and the // OpenTUI answers SIGHUP and SIGTERM by tearing the screen down without exiting, and the
// session's socket would keep a closed terminal's t3tui running for good. // session's socket would keep a closed terminal's t3tui running for good.
// The terminal is restored once `closed` settles, after the destroy event.
renderer.once("destroy", () => { renderer.once("destroy", () => {
void Promise.race([session.stop(), Bun.sleep(1000)]).finally(() => process.exit(0)); void Promise.allSettled([Promise.race([session.stop(), Bun.sleep(1000)]), renderer.closed]).finally(() => process.exit(0));
}); });
// Bun collects so lazily that a streaming thread takes t3tui past 500 MB of garbage. A full // Bun collects so lazily that a streaming thread takes t3tui past 500 MB of garbage. A full
// collection pauses for up to ~150 ms, so it waits for a few seconds without keys or clicks. // collection pauses for up to ~150 ms, so it waits for a few seconds without keys or clicks.
+1 -1
View File
@@ -637,7 +637,7 @@ export function App(props: { readonly session: T3Session; readonly config: T3tui
const quit = () => { const quit = () => {
void session.stop().finally(() => { void session.stop().finally(() => {
renderer.destroy(); renderer.destroy();
process.exit(0); void renderer.closed.finally(() => process.exit(0));
}); });
}; };