use crate::*; pub struct InkedFragment { pub string: String, pub colour: ColorSpec, } impl InkedFragment { pub fn from(string: impl Into) -> Self { Self { string: string.into(), colour: ColorSpec::new(), } } pub fn to_string(self) -> InkedString { let mut string = InkedString::new(); string.push(self); string } pub fn print(self) { self.to_string().print(); } pub fn println(self) { self.to_string().println(); } pub fn eprint(self) { self.to_string().eprint(); } pub fn eprintln(self) { self.to_string().eprintln(); } // ---------------------------------------- pub fn set_colour(mut self, colour: Option) -> Self { match colour { Some(colour) => self.colour.set_fg(Some(colour.into())), None => self.colour.set_fg(None), }; self } pub fn set_bold(mut self, bold: bool) -> Self { self.colour.set_bold(bold); self } pub fn set_dim(mut self, dim: bool) -> Self { self.colour.set_dimmed(dim); self } // ---------------------------------------- pub fn black(mut self) -> Self { self.colour.set_fg(Some(Color::Black)); self } pub fn red(mut self) -> Self { self.colour.set_fg(Some(Color::Red)); self } pub fn green(mut self) -> Self { self.colour.set_fg(Some(Color::Green)); self } pub fn yellow(mut self) -> Self { self.colour.set_fg(Some(Color::Yellow)); self } pub fn blue(mut self) -> Self { self.colour.set_fg(Some(Color::Blue)); self } pub fn magenta(mut self) -> Self { self.colour.set_fg(Some(Color::Magenta)); self } pub fn cyan(mut self) -> Self { self.colour.set_fg(Some(Color::Cyan)); self } pub fn white(mut self) -> Self { self.colour.set_fg(Some(Color::White)); self } pub fn bold(mut self) -> Self { self.colour.set_bold(true); self } pub fn dim(mut self) -> Self { self.colour.set_dimmed(true); self } } impl From for InkedFragment { fn from(string: std::string::String) -> Self { Self { string, colour: ColorSpec::new(), } } }