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 owo_colors::*;
use ansi_str::AnsiStr;
let hello = "Hello World!".red().to_string();
let (hello, world) = hello.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.
let hello1 = "Hello World!".red();
let hello2 = hello.ansi_get(..).unwrap();
assert_eq!(hello1, hello2)Structs
An structure which represents a text and it’s grafic settings.
An Iterator which produces a AnsiBlock. It’s created from get_blocks function.
An object which can be used to produce a ansi sequences which ends the grafic mode, through the std::fmt::Display.
An object which can be used to produce a ansi sequences which sets the grafic mode, through the std::fmt::Display.
An Iterator over matches. Created with the method AnsiStr::ansi_split.
Traits
AnsiStr represents a list of functions to work with colored strings defined as ANSI control sequences.