Crate ansi_str

Source
Expand description

§ansi_str

A library which provides a set of methods to work with strings escaped with ansi 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).

§Example

use ansi_str::AnsiStr;

let text = String::from("\u{1b}[31mHello World!\u{1b}[39m");
let (hello, world) = text.ansi_split_at(6);

println!("{}", hello);
println!("{}", world);

§Note

The library doesn’t guarantee to keep style of usage of ansi sequences.

For example if your string is "\u{1b}[31;40mTEXT\u{1b}[0m" and you will call get method. It may not use "\u{1b}[31;40m" but it use it as "\u{1b}[31m" and "\u{1b}[40m".

Why that matters is because for example the following code example is not guaranteed to be true.

use ansi_str::AnsiStr;

pub fn main() {
    let text = "\u{1b}[31mHello World!\u{1b}[0m";
    let text1 = hello1.ansi_get(..).unwrap();
    assert_eq!(text, text1)
}

Structs§

AnsiBlock
An structure which represents a text and it’s grafic settings.
AnsiBlockIter
An Iterator which produces a AnsiBlock. It’s created from get_blocks function.
AnsiSequenceEnd
An object which can be used to produce a ansi sequences which ends the grafic mode, through the std::fmt::Display.
AnsiSequenceStart
An object which can be used to produce a ansi sequences which sets the grafic mode, through the std::fmt::Display.
AnsiSplit
An Iterator over matches. Created with the method AnsiStr::ansi_split.
Style
A style is a structure which contains a flags about a ANSI styles where set.

Enums§

Color
A color is one specific type of ANSI escape code, and can refer to either the foreground or background color.

Traits§

AnsiStr
AnsiStr represents a list of functions to work with colored strings defined as ANSI control sequences.

Functions§

get_blocks
This function returns a Iterator which produces a AnsiBlock.