18 lines
361 B
Rust
18 lines
361 B
Rust
|
use std::fmt::Display;
|
||
|
|
||
|
use crate::ESCAPE;
|
||
|
|
||
|
pub struct Rgb(pub u8, pub u8, pub u8);
|
||
|
|
||
|
impl Rgb {
|
||
|
pub fn to_ansi(&self) -> String {
|
||
|
format!("{ESCAPE}[38;2;{};{};{}m", self.0, self.1, self.2)
|
||
|
}
|
||
|
}
|
||
|
|
||
|
impl Display for Rgb {
|
||
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||
|
f.write_str(&format!("rgb({},{},{})", self.0, self.1, self.2))
|
||
|
}
|
||
|
}
|