From 1399112379fd9deafa09c36bf1b1fc952cf4f41c Mon Sep 17 00:00:00 2001 From: Callum Alpass Date: Tue, 3 Nov 2026 02:09:44 +1100 Subject: [PATCH] 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. --- src/bin.ts | 3 ++- src/ui/App.tsx | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/bin.ts b/src/bin.ts index a6f7881..a08591b 100755 --- a/src/bin.ts +++ b/src/bin.ts @@ -149,8 +149,9 @@ async function runUi(attachNeedle?: string) { const renderer = await createCliRenderer({ exitOnCtrlC: false, useMouse: true, useKittyKeyboard: {} }); // 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. + // The terminal is restored once `closed` settles, after the destroy event. 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 // collection pauses for up to ~150 ms, so it waits for a few seconds without keys or clicks. diff --git a/src/ui/App.tsx b/src/ui/App.tsx index 334ac05..b1afd4e 100644 --- a/src/ui/App.tsx +++ b/src/ui/App.tsx @@ -637,7 +637,7 @@ export function App(props: { readonly session: T3Session; readonly config: T3tui const quit = () => { void session.stop().finally(() => { renderer.destroy(); - process.exit(0); + void renderer.closed.finally(() => process.exit(0)); }); };