ui/ansi library

ANSI styling, and helpers that measure, truncate and wrap styled text by the number of terminal columns it takes up.

Classes

Style
Text styles. Every helper returns text unchanged when enabled is false, so callers never need to check whether color is on.

Functions

displayWidth(String text) → int
Columns text takes up on screen, ignoring escape sequences.
padRight(String text, int width) → String
Pads text with spaces on the right to width columns.
runeWidth(int rune) → int
Columns taken by rune: 0 for control and combining characters, 2 for wide East Asian characters and most emoji, 1 otherwise.
truncate(String text, int width, {String ellipsis = '…'}) → String
Shortens text to at most width columns, ending it with ellipsis.
wrapText(String text, int width) → List<String>
Word-wraps text to width columns. Escape sequences are kept and take no space; words longer than a line are broken.