use crate::{ColorStyle, Gradient, StyledText, RGB};
pub trait Colorize: Into<StyledText> {
fn fg<C: Into<ColorStyle>>(&self, color: C) -> StyledText;
fn bg<C: Into<ColorStyle>>(&self, color: C) -> StyledText;
fn fg_gray(&self, x: u8) -> StyledText;
fn bg_gray(&self, x: u8) -> StyledText;
fn fg_gradient<C: Into<RGB>>(&self, start: C, end: C) -> StyledText;
fn bg_gradient<C: Into<RGB>>(&self, start: C, end: C) -> StyledText;
}
impl Colorize for StyledText {
fn fg<C: Into<ColorStyle>>(&self, color: C) -> StyledText {
self.with_foreground_color(color)
}
fn bg<C: Into<ColorStyle>>(&self, color: C) -> StyledText {
self.with_background_color(color)
}
fn fg_gray(&self, x: u8) -> StyledText {
self.with_foreground_color(RGB::gray(x))
}
fn bg_gray(&self, x: u8) -> StyledText {
self.with_background_color(RGB::gray(x))
}
fn fg_gradient<C: Into<RGB>>(&self, start: C, end: C) -> StyledText {
self.with_foreground_color(Gradient::new(start.into(), end.into()))
}
fn bg_gradient<C: Into<RGB>>(&self, start: C, end: C) -> StyledText {
self.with_background_color(Gradient::new(start.into(), end.into()))
}
}
impl Colorize for &str {
fn fg<C: Into<ColorStyle>>(&self, color: C) -> StyledText {
StyledText::new(self).with_foreground_color(color)
}
fn bg<C: Into<ColorStyle>>(&self, color: C) -> StyledText {
StyledText::new(self).with_background_color(color)
}
fn fg_gray(&self, x: u8) -> StyledText {
StyledText::new(self).with_foreground_color(RGB::gray(x))
}
fn bg_gray(&self, x: u8) -> StyledText {
StyledText::new(self).with_background_color(RGB::gray(x))
}
fn fg_gradient<C: Into<RGB>>(&self, start: C, end: C) -> StyledText {
StyledText::new(self).with_foreground_color(Gradient::new(start.into(), end.into()))
}
fn bg_gradient<C: Into<RGB>>(&self, start: C, end: C) -> StyledText {
StyledText::new(self).with_background_color(Gradient::new(start.into(), end.into()))
}
}
impl Colorize for String {
fn fg<C: Into<ColorStyle>>(&self, color: C) -> StyledText {
StyledText::new(self).with_foreground_color(color)
}
fn bg<C: Into<ColorStyle>>(&self, color: C) -> StyledText {
StyledText::new(self).with_background_color(color)
}
fn fg_gray(&self, x: u8) -> StyledText {
StyledText::new(self).with_foreground_color(RGB::gray(x))
}
fn bg_gray(&self, x: u8) -> StyledText {
StyledText::new(self).with_background_color(RGB::gray(x))
}
fn fg_gradient<C: Into<RGB>>(&self, start: C, end: C) -> StyledText {
StyledText::new(self).with_foreground_color(Gradient::new(start.into(), end.into()))
}
fn bg_gradient<C: Into<RGB>>(&self, start: C, end: C) -> StyledText {
StyledText::new(self).with_background_color(Gradient::new(start.into(), end.into()))
}
}