pub trait Colorizer {
// Required methods
fn colorize(&self, code: &str) -> String;
fn trim_ansi(&self) -> String;
fn len_ansi(&self) -> usize;
}
Expand description
Add ANSI colour escape codes to the given text for printing coloured text in terminal.
Required Methods§
sourcefn colorize(&self, code: &str) -> String
fn colorize(&self, code: &str) -> String
Add ANSI colour escape codes to the given text.
Example
use kdam::term::Colorizer;
// ANSI [8-16; 4-bit]
println!("{}", "hello world!".colorize("bold red"));
println!("{}", "hello world!".colorize("bright white on blue"));
// ANSI [256; 8-bit]
println!("{}", "hello world!".colorize("ansi(200)"));
println!("{}", "hello world!".colorize("ansi(0) on ansi(255)"));
// True Colours [(0-255, 0-255, 0-255); 24-bit]
println!("{}{}",
"hello".colorize("#171717 on #00de6d"),
" world!".colorize("#ffffff on #007272")
);
println!("{}{}",
"hello".colorize("rgb(23,23,23) on rgb(0,255,109)"),
" world!".colorize("rgb(255,255,255) on rgb(0,144,144)")
);