Lifecycle

Starting, pausing, resuming and cleaning up.

Lifecycle

The renderer’s lifecycle methods make startup, suspension and teardown deterministic. Always call destroy when your application exits to release resources and restore the terminal state. You can customise which signals cause destruction and disable automatic Ctrl+C handling.

Use start to begin the render loop, pause to suspend it temporarily (for example during heavy computation) and resume to continue. Provide an onDestroy callback to clean up application‑specific resources when the renderer exits.

const renderer = await createCliRenderer()
renderer.start()
process.on("uncaughtException", (err) => {
  console.error(err)
  renderer.destroy()
})
renderer.onDestroy(() => {
  console.log("Clean up")
})
setTimeout(() => renderer.destroy(), 1000)

It’s common to treat destroy as the single “shutdown hook” for your app: close files, stop timers, and flush logs there.