Running in a Terminal
Run the same dashboard full-screen in a terminal with text run.
In this chapter
- `text run`
- Quit with `q`
- Your own CLI
- What's different
text run runs the same app in a terminal. Layout, components, keymaps and route handlers are shared, and the output is truecolor ANSI instead of %c CSS spans.
text run
Add a script and run it:
"scripts": { "dev": "text dev", "build": "text build",Removed: "start": "text start"Added: "start": "text start",Added: "tui": "text run" },bun run tui # render ./app at /bun run tui -- --path /deployments # start on another routetext 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, and same-origin fetch("/api/…") calls run your route handlers in-process. Ctrl+C quits and restores your scrollback. It needs Bun.
Quit with q
Terminal users expect q. useApp().exit() unmounts the app and restores the terminal; in the browser it unmounts the console app.
Added: import { useApp } from "@textjs/next";export default function RootLayout({ children }: { children?: ReactNode }) {Added: const app = useApp(); useInput((e) => { if (e.key === "backspace") router.back();Added: if (e.input === "q") app.exit(); });Your own CLI
For a single component, use renderToTerminal:
import { renderToTerminal } from "@textjs/next/terminal";import DeploymentsPage from "./app/deployments/page";const app = await renderToTerminal(<DeploymentsPage />);await app.waitUntilExit();What's different
Terminals repaint faster (up to 60fps instead of ~15) and size the grid to the window instead of the docked console. Images need pixel data instead of a URL. Everything else, including this dashboard, is the same code.
Try it
This is Acme Deploys at the end of the chapter, running in DevTools. Click the pad, then use the keys below.
Open the console
The app renders in DevTools. Then click here and press Enter.
Open on a desktop
This demo renders in the Chrome DevTools console, which needs a desktop browser.
Quiz
2 questionsAnswer every question to complete the chapter.