beamtea_util (beamtea v0.1.0)

View Source

Small shared helpers for beamtea bubbles.

Summary

Functions

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 code points, adding an ellipsis when cut.

The number of visible columns in a string, ignoring ANSI escapes. (Counts code points; wide characters are treated as width 1.)

Functions

format_clock(Ms)

-spec format_clock(integer()) -> iodata().

Format milliseconds as MM:SS (or HH:MM:SS past an hour).

format_stopwatch(Ms)

-spec format_stopwatch(integer()) -> iodata().

Format milliseconds as MM:SS.CS (centiseconds) — for stopwatches.

pad_right(IoData, Width)

-spec pad_right(iodata(), non_neg_integer()) -> iodata().

Right-pad an iodata string with spaces to Width code points (never truncates).

pad_visible(IoData, Width)

-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).

strip_ansi(IoData)

-spec strip_ansi(unicode:chardata()) -> binary().

Remove ANSI escape sequences (SGR colours, cursor moves, …) from a string, leaving only the visible characters.

truncate(IoData, Max)

-spec truncate(iodata(), non_neg_integer()) -> binary().

Truncate an iodata string to at most Max code points, adding an ellipsis when cut.

visible_width(IoData)

-spec visible_width(unicode:chardata()) -> non_neg_integer().

The number of visible columns in a string, ignoring ANSI escapes. (Counts code points; wide characters are treated as width 1.)