---
title: "Long Lists"
description: "Terminal apps, written in TypeScript and compiled to native executables with scriptc."
canonical_url: "https://tui-sdk.dev/docs/guides/long-lists"
---
# Long Lists

A `ScrollArea` given a `total` and a body draws only the rows in view, so its list can be as long as memory allows. `createFilter` finds the lines that match a query without making typing wait: each frame, `update(lines, query)` tests lines for a few milliseconds and keeps the matches found so far, and `count` and `at(index)` say what they are. It reads the list as one that only grows, like a log, so only new lines are tested, and a query that adds to the last tests only the lines that matched it. A query without a capital letter ignores case, and one with a capital matches it. `drawMatches` draws a line with its matches in the theme's `match` style.

```ts
import { createFilter, drawMatches, type Frame, runApp, ScrollArea } from "tui"

const lines = Array.from({ length: 1_000_000 }, (_, index) => `line ${index}`)
const filter = createFilter()
let query = "42"

function view(frame: Frame) {
  filter.update(lines, query)
  ScrollArea.Root(frame, { id: "log", total: filter.count, stickToEnd: true }, (area) =>
    ScrollArea.Viewport(area, frame.rect, (viewport) => {
      const offset = viewport.api.offset()
      for (let row = 0; row < viewport.rect.rows && offset + row < filter.count; row++) {
        const line = lines[filter.at(offset + row)] ?? ""
        drawMatches(frame, viewport.rect.x, viewport.rect.y + row, line, query, 0, viewport.rect)
      }
    }),
  )
}

runApp({ view })
```


[`million.ts`](https://github.com/vercel-labs/tui/blob/main/examples/million.ts) makes a log of a million lines, adds two thousand a second, and filters it as you type at 60 fps.

The HTML page runs [`examples/million.ts`](https://github.com/vercel-labs/tui/blob/main/examples/million.ts) here, in a terminal in the page.
A `Table` of many rows also stays quick: it finds the highlighted row without searching them all.
