ANSI-aware terminal-cell measurement and layout.
Terminal width differs from UTF-8 byte length and Unicode rune count. These helpers treat combining marks and joiners as zero-width, common East Asian and emoji characters as two cells, and joined emoji as one grapheme.
Types
TextAlignment = enum alignLeft, alignCenter, alignRight
- Horizontal alignment used by padAnsi. Source Edit
Procs
proc displayWidth(value: string): int {....raises: [], tags: [], forbids: [].}
- Returns the width of the widest line in terminal cells. ANSI controls do not count; combining marks, variation selectors, and joiners do not add a cell; common East Asian and emoji graphemes occupy two cells. Source Edit
proc truncateAnsi(value: string; maxWidth: int; suffix = "…"): string {. ...raises: [ValueError], tags: [], forbids: [].}
- Truncates a single display line and appends suffix when needed. Source Edit
proc wrapAnsi(value: string; width: int; mode = wrapWords): seq[string] {. ...raises: [ValueError], tags: [], forbids: [].}
- Wraps styled text to width cells. Explicit newlines are honored and active SGR and OSC-8 hyperlink state is restored on each produced line. Whitespace at a word-wrap boundary is omitted. Source Edit