#ansi #ansi-term #color #terminal #cli-color

ansi-str

A library which provides a set of methods to work with ANSI strings

11 releases (7 breaking)

0.8.0 Jun 2, 2023
0.7.2 Nov 29, 2022
0.6.0 Nov 28, 2022
0.3.0 Jul 19, 2022
0.1.1 Jan 31, 2022

#137 in Command-line interface

Download history 8766/week @ 2023-11-21 8651/week @ 2023-11-28 7255/week @ 2023-12-05 7879/week @ 2023-12-12 5448/week @ 2023-12-19 4494/week @ 2023-12-26 7853/week @ 2024-01-02 6972/week @ 2024-01-09 7908/week @ 2024-01-16 8730/week @ 2024-01-23 8679/week @ 2024-01-30 8988/week @ 2024-02-06 7125/week @ 2024-02-13 8065/week @ 2024-02-20 8198/week @ 2024-02-27 8349/week @ 2024-03-05

32,940 downloads per month
Used in 79 crates (4 directly)

MIT license

105KB
2K SLoC

ansi-str Build Status codecov Crate docs.rs

This is a library provides a set of methods to work with strings escaped with ansi code sequences.

It's an agnostic library in regard to different color libraries. Therefore it can be used with any library (e.g. owo-colors, nu-ansi-term).

Usage

use ansi_str::AnsiStr;
use owo_colors::{colors::*, OwoColorize};

pub fn main() {
    let text = "When the night has come"
        .fg::<Red>()
        .bg::<Cyan>()
        .bold()
        .to_string();

    let cut = text.ansi_get(5..).expect("ansi_get mustn't fail");

    println!("{}", text);
    println!("{}", cut);
}

Running this code will result in the following output.

image

For more examples, you check out the examples directory.

Note

The library has derivatived from zhiburt/ansi-cut

Dependencies

~1.5MB
~23K SLoC