From 4bf61a8fde618003c88d15071c9d6a50654e3dd9 Mon Sep 17 00:00:00 2001 From: Oliver Bryan Date: Mon, 2 Feb 2026 19:57:43 +0000 Subject: [PATCH] cleanup properly --- cli/main.tsx | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/cli/main.tsx b/cli/main.tsx index dad2dbe3..7e2b471a 100644 --- a/cli/main.tsx +++ b/cli/main.tsx @@ -1,8 +1,30 @@ import { createCliRenderer } from "@opentui/core"; -import { createRoot, useKeyboard, useTerminalDimensions } from "@opentui/react"; +import { + createRoot, + useKeyboard, + useRenderer, + useTerminalDimensions, +} from "@opentui/react"; +import { useEffect } from "react"; function App() { const { width, height } = useTerminalDimensions(); + const renderer = useRenderer(); + + useEffect(() => { + const handleExit = () => { + renderer.cleanup(); + process.exit(0); + }; + + process.on("SIGINT", handleExit); + process.on("SIGTERM", handleExit); + + return () => { + process.off("SIGINT", handleExit); + process.off("SIGTERM", handleExit); + }; + }, [renderer]); useKeyboard((key) => { if ( @@ -10,6 +32,7 @@ function App() { key.name === "escape" || (key.ctrl && key.name === "c") ) { + renderer.cleanup(); process.exit(0); } });