---
title: "Text and Width"
description: "Terminal apps, written in TypeScript and compiled to native executables with scriptc."
canonical_url: "https://tui-sdk.dev/docs/reference/text"
---
# Text and Width

tui measures text in terminal columns, not JavaScript string length. A wide character takes two columns, a combining mark takes none, and a family emoji is one cluster. The width tables come from Unicode 17.

- `widthOf(text, ambiguousWidth?)` returns the columns `text` takes on one line. Control characters count as one column, as they are drawn.
- `wrap(text, columns, ambiguousWidth?)` returns the text in lines of at most `columns`. It breaks at spaces where it can and inside a word only when the word is longer than a line. Its own line breaks start new lines, and a tab is a space. A character wider than `columns` goes on a line by itself.
- `truncate(text, columns, ellipsis?, ambiguousWidth?)` cuts text to at most `columns`, ending in `…` when anything was cut.
- `clusterAt(text, index, ambiguousWidth?)` packs the cluster that starts at UTF-16 `index`.
- `clusterEnd(packed)` returns the index after the cluster.
- `clusterWidth(packed)` returns the columns the cluster takes.
- `codePointWidth(codePoint, ambiguousWidth?)` returns the columns one code point takes.
- `isPictographic(codePoint)` says whether a code point is pictographic.
- `unicodeVersion` is the Unicode version the tables were built from.

```ts
import { clusterAt, clusterEnd, clusterWidth, truncate, unicodeVersion, widthOf, wrap } from "tui"

const text = "👩‍💻 tiếng Việt"
console.log(unicodeVersion, widthOf(text))
console.log(wrap("Build terminal interfaces in TypeScript", 12))
console.log(truncate("Build terminal interfaces", 12))
const packed = clusterAt(text, 0)
console.log(clusterWidth(packed), clusterEnd(packed))
```

`ambiguousWidth` is 1 by default. Set it to 2 for terminals that draw ambiguous East Asian characters wide.
