---
title: "Quick Start"
description: "Terminal apps, written in TypeScript and compiled to native executables with scriptc."
canonical_url: "https://tui-sdk.dev/docs/quick-start"
---
# Quick Start

This walkthrough builds an app with `runApp`, an `Input` at the bottom, and a `ScrollArea` for the messages. `view` draws every frame from the app's state.

### 1. Create the app

Add `"type": "module"` to `package.json`, so `app.ts` runs as an ES module.

Save this as `app.ts`:

```ts
import { type Frame, Input, runApp, ScrollArea, split } from "tui"

const messages: string[] = []
let draft = ""

function view(frame: Frame) {
  const [log, entry] = split(frame.rect, "rows", [-1, 1])
  Input.Root(
    frame,
    {
      id: "message",
      label: "Message",
      value: draft,
      placeholder: "Type a message",
      onValueChange: (value) => {
        draft = value
      },
      onSubmit: (value) => {
        if (value.trim()) {
          messages.push(value.trim())
        }
        draft = ""
        frame.redraw()
      },
    },
    (root) => Input.Field(root, entry),
  )
  ScrollArea.Root(frame, { id: "log", label: "Log", lines: messages, stickToEnd: true }, (area) =>
    ScrollArea.Viewport(area, log),
  )
}

runApp({ view })
```

Run it with Node.js:

```console
$ node app.ts
```

Type a message and press Enter to add it to the log. The log stays at its newest line while it is at the end. Ctrl+C stops the app and restores the terminal.

`runApp` returns the app immediately; a timer or other code that changes state calls `app.redraw()` to draw the change. The `Input` is drawn before the `ScrollArea` because the first focusable part drawn takes the focus.

The HTML page runs [`examples/hello.ts`](https://github.com/vercel-labs/tui/blob/main/examples/hello.ts) here, in a terminal in the page.

### 2. Build a native executable

Building needs clang and a linker. On Debian or Ubuntu:

```console
$ sudo apt-get install clang lld binutils libc6-dev
```

Then build:

```console
$ npx scriptc build app.ts -o app
$ ./app
```

### 3. Test without a terminal

`createTestApp` runs the same `view` on a screen of its own. A test can press keys, type, and read the screen back, so it needs no terminal and runs in CI.

```ts
import assert from "node:assert/strict"
import { createTestApp } from "tui"

// `view` and `messages` from the app above.
const app = createTestApp({ columns: 20, rows: 4, view })
app.type("hello")
app.press("enter")
assert.equal(app.screen()[0], "hello")
```

Each key is drawn before the next one is sent, so what the test reads is the current screen.

## Next steps

- [Rendering model](/docs/concepts/rendering-model): How a frame is drawn, and what reaches the terminal.
- [Components](/docs/concepts/components): The state, focus, and change contract every component shares.
- [Agents](/docs/guides/agents): Let an agent use the app over MCP while it runs.
- [Examples](/docs/examples): Complete programs, running in your browser.
