use std::fmt;
use crate::color::Color;
use crate::gradient::Gradient;
use crate::style::Style;
use crate::styled::Styled;
pub trait Colorize: fmt::Display + Sized {
fn style(self, s: Style) -> Styled<Self> {
Styled::new(self, s)
}
fn black(self) -> Styled<Self> {
self.style(Style::new().black())
}
fn red(self) -> Styled<Self> {
self.style(Style::new().red())
}
fn green(self) -> Styled<Self> {
self.style(Style::new().green())
}
fn yellow(self) -> Styled<Self> {
self.style(Style::new().yellow())
}
fn blue(self) -> Styled<Self> {
self.style(Style::new().blue())
}
fn magenta(self) -> Styled<Self> {
self.style(Style::new().magenta())
}
fn cyan(self) -> Styled<Self> {
self.style(Style::new().cyan())
}
fn white(self) -> Styled<Self> {
self.style(Style::new().white())
}
fn bright_black(self) -> Styled<Self> {
self.style(Style::new().bright_black())
}
fn bright_red(self) -> Styled<Self> {
self.style(Style::new().bright_red())
}
fn bright_green(self) -> Styled<Self> {
self.style(Style::new().bright_green())
}
fn bright_yellow(self) -> Styled<Self> {
self.style(Style::new().bright_yellow())
}
fn bright_blue(self) -> Styled<Self> {
self.style(Style::new().bright_blue())
}
fn bright_magenta(self) -> Styled<Self> {
self.style(Style::new().bright_magenta())
}
fn bright_cyan(self) -> Styled<Self> {
self.style(Style::new().bright_cyan())
}
fn bright_white(self) -> Styled<Self> {
self.style(Style::new().bright_white())
}
fn rgb(self, r: u8, g: u8, b: u8) -> Styled<Self> {
self.style(Style::new().rgb(r, g, b))
}
fn hex(self, hex: &str) -> Styled<Self> {
self.style(Style::new().hex(hex))
}
fn xterm(self, idx: u8) -> Styled<Self> {
self.style(Style::new().fg(Color::Xterm(idx)))
}
fn on_black(self) -> Styled<Self> {
self.style(Style::new().on_black())
}
fn on_red(self) -> Styled<Self> {
self.style(Style::new().on_red())
}
fn on_green(self) -> Styled<Self> {
self.style(Style::new().on_green())
}
fn on_yellow(self) -> Styled<Self> {
self.style(Style::new().on_yellow())
}
fn on_blue(self) -> Styled<Self> {
self.style(Style::new().on_blue())
}
fn on_magenta(self) -> Styled<Self> {
self.style(Style::new().on_magenta())
}
fn on_cyan(self) -> Styled<Self> {
self.style(Style::new().on_cyan())
}
fn on_white(self) -> Styled<Self> {
self.style(Style::new().on_white())
}
fn on_bright_black(self) -> Styled<Self> {
self.style(Style::new().on_bright_black())
}
fn on_bright_red(self) -> Styled<Self> {
self.style(Style::new().on_bright_red())
}
fn on_bright_green(self) -> Styled<Self> {
self.style(Style::new().on_bright_green())
}
fn on_bright_yellow(self) -> Styled<Self> {
self.style(Style::new().on_bright_yellow())
}
fn on_bright_blue(self) -> Styled<Self> {
self.style(Style::new().on_bright_blue())
}
fn on_bright_magenta(self) -> Styled<Self> {
self.style(Style::new().on_bright_magenta())
}
fn on_bright_cyan(self) -> Styled<Self> {
self.style(Style::new().on_bright_cyan())
}
fn on_bright_white(self) -> Styled<Self> {
self.style(Style::new().on_bright_white())
}
fn on_rgb(self, r: u8, g: u8, b: u8) -> Styled<Self> {
self.style(Style::new().on_rgb(r, g, b))
}
fn on_hex(self, hex: &str) -> Styled<Self> {
self.style(Style::new().on_hex(hex))
}
fn bold(self) -> Styled<Self> {
self.style(Style::new().bold())
}
fn dim(self) -> Styled<Self> {
self.style(Style::new().dim())
}
fn italic(self) -> Styled<Self> {
self.style(Style::new().italic())
}
fn underline(self) -> Styled<Self> {
self.style(Style::new().underline())
}
fn blink(self) -> Styled<Self> {
self.style(Style::new().blink())
}
fn blink_fast(self) -> Styled<Self> {
self.style(Style::new().blink_fast())
}
fn reverse(self) -> Styled<Self> {
self.style(Style::new().reverse())
}
fn hidden(self) -> Styled<Self> {
self.style(Style::new().hidden())
}
fn strikethrough(self) -> Styled<Self> {
self.style(Style::new().strikethrough())
}
fn gradient(self, from: Color, to: Color) -> Gradient {
Gradient::new(self.to_string(), from, to)
}
fn gradient_multi(self, stops: Vec<Color>) -> Gradient {
Gradient::multi_stop(self.to_string(), stops)
}
}
impl<T: fmt::Display> Colorize for T {}
impl<T: fmt::Display> Styled<T> {
pub fn red(mut self) -> Self {
self.style = self.style.red();
self
}
pub fn green(mut self) -> Self {
self.style = self.style.green();
self
}
pub fn yellow(mut self) -> Self {
self.style = self.style.yellow();
self
}
pub fn blue(mut self) -> Self {
self.style = self.style.blue();
self
}
pub fn magenta(mut self) -> Self {
self.style = self.style.magenta();
self
}
pub fn cyan(mut self) -> Self {
self.style = self.style.cyan();
self
}
pub fn white(mut self) -> Self {
self.style = self.style.white();
self
}
pub fn black(mut self) -> Self {
self.style = self.style.black();
self
}
pub fn bright_red(mut self) -> Self {
self.style = self.style.bright_red();
self
}
pub fn bright_green(mut self) -> Self {
self.style = self.style.bright_green();
self
}
pub fn bright_yellow(mut self) -> Self {
self.style = self.style.bright_yellow();
self
}
pub fn bright_blue(mut self) -> Self {
self.style = self.style.bright_blue();
self
}
pub fn bright_magenta(mut self) -> Self {
self.style = self.style.bright_magenta();
self
}
pub fn bright_cyan(mut self) -> Self {
self.style = self.style.bright_cyan();
self
}
pub fn bright_white(mut self) -> Self {
self.style = self.style.bright_white();
self
}
pub fn bright_black(mut self) -> Self {
self.style = self.style.bright_black();
self
}
pub fn on_black(mut self) -> Self {
self.style = self.style.on_black();
self
}
pub fn on_red(mut self) -> Self {
self.style = self.style.on_red();
self
}
pub fn on_green(mut self) -> Self {
self.style = self.style.on_green();
self
}
pub fn on_yellow(mut self) -> Self {
self.style = self.style.on_yellow();
self
}
pub fn on_blue(mut self) -> Self {
self.style = self.style.on_blue();
self
}
pub fn on_magenta(mut self) -> Self {
self.style = self.style.on_magenta();
self
}
pub fn on_cyan(mut self) -> Self {
self.style = self.style.on_cyan();
self
}
pub fn on_white(mut self) -> Self {
self.style = self.style.on_white();
self
}
pub fn on_bright_black(mut self) -> Self {
self.style = self.style.on_bright_black();
self
}
pub fn on_bright_red(mut self) -> Self {
self.style = self.style.on_bright_red();
self
}
pub fn on_bright_green(mut self) -> Self {
self.style = self.style.on_bright_green();
self
}
pub fn on_bright_yellow(mut self) -> Self {
self.style = self.style.on_bright_yellow();
self
}
pub fn on_bright_blue(mut self) -> Self {
self.style = self.style.on_bright_blue();
self
}
pub fn on_bright_magenta(mut self) -> Self {
self.style = self.style.on_bright_magenta();
self
}
pub fn on_bright_cyan(mut self) -> Self {
self.style = self.style.on_bright_cyan();
self
}
pub fn on_bright_white(mut self) -> Self {
self.style = self.style.on_bright_white();
self
}
pub fn rgb(mut self, r: u8, g: u8, b: u8) -> Self {
self.style = self.style.rgb(r, g, b);
self
}
pub fn on_rgb(mut self, r: u8, g: u8, b: u8) -> Self {
self.style = self.style.on_rgb(r, g, b);
self
}
pub fn hex(mut self, h: &str) -> Self {
self.style = self.style.hex(h);
self
}
pub fn on_hex(mut self, h: &str) -> Self {
self.style = self.style.on_hex(h);
self
}
pub fn bold(mut self) -> Self {
self.style = self.style.bold();
self
}
pub fn dim(mut self) -> Self {
self.style = self.style.dim();
self
}
pub fn italic(mut self) -> Self {
self.style = self.style.italic();
self
}
pub fn underline(mut self) -> Self {
self.style = self.style.underline();
self
}
pub fn blink(mut self) -> Self {
self.style = self.style.blink();
self
}
pub fn blink_fast(mut self) -> Self {
self.style = self.style.blink_fast();
self
}
pub fn reverse(mut self) -> Self {
self.style = self.style.reverse();
self
}
pub fn hidden(mut self) -> Self {
self.style = self.style.hidden();
self
}
pub fn strikethrough(mut self) -> Self {
self.style = self.style.strikethrough();
self
}
}