Crate fast_strip_ansi

Crate fast_strip_ansi 

Source
Expand description

§fast-strip-ansi

A performance-optimized ANSI escape sequence stripper, built on top of the vt-push-parser crate.

Full VT-100/ANSI support.

No startup cost for regex compilation.

§Usage

use fast_strip_ansi::*;
let input = b"Hello, world!\x1b[31m\nHello, world!\x1b[0m";
assert_eq!(strip_ansi_bytes(input), b"Hello, world!\nHello, world!".as_slice());
let input = "Hello, world!\x1b[31m\nHello, world!\x1b[0m";
assert_eq!(strip_ansi_string(input), "Hello, world!\nHello, world!");

§Security and Correctness

fast-strip-ansi is correct and secure. It contains a true VT-100/ANSI state machine which handles corner cases not handled by other crates.

§Performance

fast-strip-ansi the fastest and most correct library for stripping ANSI escape sequences.

Note that fast-strip-ansi has wider support for ANSI escape sequences than most crates but is still the fastest option.

It is significantly faster than strip-ansi and strip-ansi-escapes in all modes.

xychart
    title "Performance"
    x-axis [fast-strip-ansi, fast-strip-ansi-callback, strip-ansi, strip-ansi-escapes]
    y-axis "Time (in µs)" 0 --> 100
    bar [22.12, 11.26, 39.05, 292.5]
    bar [11.89, 6.841, 19.21, 277.4]

%% Your markdown viewer may not render the chart correctly.
%% View in a mermaid chart viewer like <https://mermaid.live>

§Raw performance data:

from cargo bench on an M3 MacBook Pro

0 suffix means no ansi content, 100 means significant ansi content

comparisonfastestmedian
fast_strip_ansi_crate_06.54 µs6.937 µs
fast_strip_ansi_crate_10018.7 µs19.14 µs
fast_strip_ansi_crate_bytes_06.624 µs6.707 µs
fast_strip_ansi_crate_bytes_10010.83 µs10.95 µs
fast_strip_ansi_crate_callback_06.333 µs6.416 µs
fast_strip_ansi_crate_callback_10010.37 µs10.66 µs
strip_ansi_crate_015.33 µs15.95 µs
strip_ansi_crate_10023.54 µs26.47 µs
strip_ansi_escapes_crate_0235.9 µs257.9 µs
strip_ansi_escapes_crate_100241.8 µs269.1 µs

Crate versions:

crateversion
fast-strip-ansilatest
strip-ansi0.1.0
strip-ansi-escapes0.2.1

Structs§

StreamingStripper
A streaming ANSI escape sequence stripper that can be fed chunks of data and yields text chunks to a callback.
Writer
A writer that strips ANSI escape sequences from the data written to it and feeds the underlying writer with the raw text chunks.

Functions§

strip_ansi_bytes
Strip ANSI escape sequences from a byte slice. If the input contains no ANSI escape sequences, the input is returned as-is.
strip_ansi_bytes_callback
Strip ANSI escape sequences from a byte slice, calling a callback for each raw text chunk.
strip_ansi_string
Strip ANSI escape sequences from a string. If the input contains no ANSI escape sequences, the input is returned as-is.