pub struct Ansi256(_);
Expand description
Predefined set of 256 colors to use with ANSI escape sequences, e.g. in terminal emulators
Example
use colorsys::{Ansi256, Rgb};
let rgb = Rgb::from_hex_str("#875fff").unwrap();
let ansi256: Ansi256 = rgb.into();
assert_eq!(ansi256.code(),99);
let green_yellow = Ansi256::new(154);
let rgb2 = green_yellow.as_rgb();
assert_eq!(rgb2.to_hex_string(), "#afff00");
let txt = format!(
"\x1b[38;5;{ansi_code}m{text}\x1b[0m",
ansi_code=green_yellow.code(),
text="my colored text"
);
println!("{}", txt);