use std::usize;
use crate::color::*;
use crate::style::StyleBuilder;
pub trait ColorPrinter {
fn print_c16(&self, foreground: usize, background: usize) -> String;
fn print_c256(&self, foreground: usize, background: usize) -> String;
fn print_24bit(&self, foreground: RGB, background: RGB) -> String;
fn warn(&self) -> String;
fn error(&self) -> String;
fn danger(&self) -> String;
fn info(&self) -> String;
fn primary(&self) -> String;
fn blink(&self) -> String;
fn underline(&self) -> String;
}
impl ColorPrinter for str {
fn print_c16(&self, foreground: usize, background: usize) -> String {
let result = StyleBuilder::new()
.csi()
.color(foreground)
.delimiter()
.color(background)
.end_sgr()
.message()
.csi()
.reset()
.end_sgr()
.build();
result.render(self)
}
fn print_c256(&self, foreground: usize, background: usize) -> String {
let result = StyleBuilder::new()
.csi()
.foreground_8bit()
.delimiter()
.color(foreground)
.delimiter()
.background_8bit()
.delimiter()
.color(background)
.end_sgr()
.message()
.csi()
.reset()
.end_sgr()
.build();
result.render(self)
}
fn error(&self) -> String {
let result = self.print_c16(FG_WHITE, BG_RED);
result
}
fn danger(&self) -> String {
let result = self.print_c16(FG_RED, BG_DEFAULT);
result
}
fn info(&self) -> String {
let result = self.print_c16(FG_GREEN, BG_DEFAULT);
result
}
fn primary(&self) -> String {
let result = self.print_c16(FG_BLUE, BG_DEFAULT);
result
}
fn warn(&self) -> String {
let result = self.print_c16(FG_YELLOW, BG_DEFAULT);
result
}
fn blink(&self) -> String {
let result = StyleBuilder::new()
.csi()
.color(FG_RED)
.delimiter()
.blink()
.end_sgr()
.message()
.csi()
.reset()
.end_sgr()
.build();
result.render(self)
}
fn underline(&self) -> String {
let result = StyleBuilder::new()
.csi()
.color(FG_YELLOW)
.delimiter()
.underline()
.end_sgr()
.message()
.csi()
.reset()
.end_sgr()
.build();
result.render(self)
}
fn print_24bit(&self, foreground: RGB, background: RGB) -> String {
let RGB(fr, fg, fb) = foreground;
let RGB(br, bg, bb) = background;
let result = StyleBuilder::new()
.csi()
.foreground_24bit()
.delimiter()
.color(fr as usize)
.delimiter()
.color(fg as usize)
.delimiter()
.color(fb as usize)
.delimiter()
.background_24bit()
.delimiter()
.color(br as usize)
.delimiter()
.color(bg as usize)
.delimiter()
.color(bb as usize)
.end_sgr()
.message()
.csi()
.reset()
.end_sgr()
.build();
result.render(self)
}
}