cansi
Catergorise ANSI - ANSI escape code parser and categoriser
See the rs docs. Look at progress and contribute on github.
cansi will parse text with ANSI escape sequences in it and return a deconstructed text with metadata around the colouring and styling. cansi is only concerned with CSI sequences, particuarly the SGR parameters. cansi will not construct escaped text, there are crates such as colored that do a great job of colouring and styling text.
Example usage
This example was done using the
coloredcrate to help with constructing the escaped text string. It will work with other tools that inject escape sequences into text strings (given they follow ANSI specification).
extern crate cansi;
extern crate colored;
use *;
use *;
use Write;
let v = &mut Vecnew;
write!
.unwrap;
let text = Stringfrom_utf8_lossy;
let result = categorise_text; // cansi function
assert_eq!; // there should be seven differently styled components
assert_eq!;
// 'Hello, ' is just defaults
assert_eq!;
// 'w' is coloured differently
assert_eq!;