beamtea_util (beamtea v0.1.2)
View SourceSmall shared helpers for beamtea bubbles.
Summary
Functions
The display width of a single code point (0, 1 or 2).
Format milliseconds as MM:SS (or HH:MM:SS past an hour).
Format milliseconds as MM:SS.CS (centiseconds) — for stopwatches.
Right-pad an iodata string with spaces to Width code points (never truncates).
Right-pad to Width *visible* columns, ignoring ANSI escapes in the width calculation (so coloured text lines up correctly).
Remove ANSI escape sequences (SGR colours, cursor moves, …) from a string, leaving only the visible characters.
Truncate an iodata string to at most Max *display columns*, adding an ellipsis when cut. Wide characters count as 2, so the result never exceeds Max columns even when it splits around emoji/CJK.
The number of *display columns* a string occupies, ignoring ANSI escapes. Uses a wcwidth (via prim_tty:npwcwidth/1), so wide characters (emoji, CJK) count as 2 and combining marks as 0 — this is what keeps borders and padding aligned around wide glyphs.
Functions
-spec char_width(char()) -> 0..2.
The display width of a single code point (0, 1 or 2).
Format milliseconds as MM:SS (or HH:MM:SS past an hour).
Format milliseconds as MM:SS.CS (centiseconds) — for stopwatches.
-spec pad_right(iodata(), non_neg_integer()) -> iodata().
Right-pad an iodata string with spaces to Width code points (never truncates).
-spec pad_visible(unicode:chardata(), non_neg_integer()) -> iodata().
Right-pad to Width *visible* columns, ignoring ANSI escapes in the width calculation (so coloured text lines up correctly).
-spec strip_ansi(unicode:chardata()) -> binary().
Remove ANSI escape sequences (SGR colours, cursor moves, …) from a string, leaving only the visible characters.
-spec truncate(iodata(), non_neg_integer()) -> binary().
Truncate an iodata string to at most Max *display columns*, adding an ellipsis when cut. Wide characters count as 2, so the result never exceeds Max columns even when it splits around emoji/CJK.
-spec visible_width(unicode:chardata()) -> non_neg_integer().
The number of *display columns* a string occupies, ignoring ANSI escapes. Uses a wcwidth (via prim_tty:npwcwidth/1), so wide characters (emoji, CJK) count as 2 and combining marks as 0 — this is what keeps borders and padding aligned around wide glyphs.