Skip to content

Commit 92cf9b8

Browse files
committed
Clean up displayWidth documentation and changeset
1 parent fc40e6f commit 92cf9b8

2 files changed

Lines changed: 8 additions & 20 deletions

File tree

‎.changeset/cli-export-display-width.md‎

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,4 @@
22
"effect": patch
33
---
44

5-
cli: export the terminal display-width measure as `CliOutput.displayWidth`
6-
7-
```ts
8-
import { CliOutput } from "effect/cli"
9-
10-
CliOutput.displayWidth("ファイル") // => 8
11-
CliOutput.displayWidth("é") // => 1
12-
CliOutput.displayWidth("1️⃣") // => 2
13-
```
14-
15-
The measure the built-in help and table rendering already use was internal, so custom formatters had to reimplement the grapheme and East Asian Width logic to line up with it. `displayWidth` is that same function, unchanged: ANSI styling is stripped first, so styled and unstyled text measure alike.
5+
Export `CliOutput.displayWidth` to measure terminal-cell widths using the same logic as built-in CLI help and tables.

‎packages/effect/src/cli/CliOutput.ts‎

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,7 @@ const stripAnsi = (text: string): string => {
381381
}
382382

383383
/**
384-
* Segments text into grapheme clusters for display width measurement.
384+
* Segments text into grapheme clusters.
385385
* @internal
386386
*/
387387
const graphemeSegmenter = new Intl.Segmenter(undefined, { granularity: "grapheme" })
@@ -418,16 +418,14 @@ const graphemeWidth = (grapheme: string): number => {
418418
/**
419419
* Measures the number of terminal cells a string occupies.
420420
*
421-
* ANSI styling is stripped first, so styled and unstyled text measure the
422-
* same. Widths are computed per grapheme: combining marks and other zero-width
423-
* code points count as `0`, emoji presentation sequences and East Asian Wide /
424-
* Fullwidth characters count as `2`, everything else counts as `1`.
421+
* **Details**
425422
*
426-
* This is the same measure the built-in help and table rendering use, so
427-
* custom formatters can line up their output with it without reimplementing
428-
* the Unicode logic.
423+
* Uses the same measurement as built-in help and table rendering. ANSI styling
424+
* is stripped before measuring graphemes: zero-width graphemes count as `0`,
425+
* emoji presentation sequences and fullwidth characters as `2`, and other
426+
* graphemes as `1`.
429427
*
430-
* **Example**
428+
* **Example** (Measuring terminal-cell widths)
431429
*
432430
* ```ts import.meta.vitest
433431
* import { CliOutput } from "effect/cli"

0 commit comments

Comments
 (0)