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)); }); };