Skip to content

ansi

ANSI escape sequences: remove them from captured output and build styled text.

strip, contains and visible_len deal with text that already has escape sequences (command output, logs); Style and Color build the sequences for colors and attributes. Nothing here decides whether a terminal supports colors: that stays with the caller.

Cargo feature ansi (enabled by default). To compile only this module:

cargo add helpers4 --no-default-features --features ansi

or in Cargo.toml:

[dependencies]
helpers4 = { version = "0.0.6", default-features = false, features = ["ansi"] }

Import path: helpers4::ansi.

ItemWhat it does
ColorA terminal color for Style.
containsWhether text contains an ANSI escape character (ESC, U+001B).
stripRemoves the ANSI escape sequences from text, leaving what a terminal would display.
StyleA text style: colors and attributes, applied to a string with paint.
visible_lenThe number of characters a terminal shows for text: its length once escape sequences are removed.