Running in a Terminal

Render an App Router app or a single component in a terminal with text run and renderToTerminal.

text run renders an App Router app in a terminal. Layout, components, keymaps and route handlers are shared with the browser. Output is truecolor ANSI instead of %c spans.

text run              # render ./app at /text run --path /logs # start on another route

Press Ctrl+C to quit. text run needs Bun.

text run

text run imports every file in app/, mounts the App Router with an in-memory history and draws it full-screen. <Link>, useRouter(), notFound() and redirect() work unchanged.

Same-origin fetch("/api/...") calls run your route.ts handlers in-process, exactly as text dev would serve them. Other URLs go to the network.

renderToTerminal

For a single component, or your own CLI:

cli.tsxtsx
import { renderToTerminal } from "@textjs/next/terminal";import { App } from "./app";const app = await renderToTerminal(<App />);await app.waitUntilExit();

useApp().exit() unmounts and restores the terminal.

OptionDescription
stdin / stdoutDefault process.stdin / process.stdout
cols / rowsFixed size (default: follow the terminal)
altScreenRestore the scrollback on exit (default true)
mouseWheel scrolling (default true)
exitOnCtrlCDefault true
fpsFrame cap (default 60)
patchConsoleHold console.* until exit (default true)
theme / transparentAs in createConsoleRoot

Output

Each frame is diffed row by row. Only changed rows are written, wrapped in synchronized-output markers so terminals that support them never show a half-drawn frame. Idle apps write nothing.

Input

Raw-mode stdin is parsed into the same events the browser produces: arrows and function keys with modifiers, Alt combinations, bracketed paste, SGR mouse wheel and the kitty keyboard protocol. TerminalInputParser and parseTerminalInput are exported if you need them elsewhere.

Differences

FeatureDevToolsTerminal
Frame pacing~15fpsUp to fps
Grid sizeDocked consoleTerminal window
<Image src>Loads via canvasUse pixels
console.logYour framesHeld until exit