use termion::{color, style};
pub(crate) trait StringAppender {
fn append_to_string(&self, string: &mut String);
}
#[derive(Debug, Copy, Clone, PartialEq)]
pub enum Color {
Black,
Red,
Green,
Yellow,
Blue,
Magenta,
Cyan,
White,
}
impl StringAppender for Color {
fn append_to_string(&self, string: &mut String) {
match *self {
Color::Black => string.push_str(&color::Fg(color::Black).to_string()),
Color::Red => string.push_str(&color::Fg(color::Red).to_string()),
Color::Green => string.push_str(&color::Fg(color::Green).to_string()),
Color::Yellow => string.push_str(&color::Fg(color::Yellow).to_string()),
Color::Blue => string.push_str(&color::Fg(color::Blue).to_string()),
Color::Magenta => string.push_str(&color::Fg(color::Magenta).to_string()),
Color::Cyan => string.push_str(&color::Fg(color::Cyan).to_string()),
Color::White => string.push_str(&color::Fg(color::White).to_string()),
}
}
}
#[derive(Debug, Copy, Clone, PartialEq)]
pub enum Style {
Bold,
Italic,
Underline,
}
impl ToString for Style {
fn to_string(&self) -> String {
match *self {
Style::Bold => style::Bold.to_string(),
Style::Italic => style::Italic.to_string(),
Style::Underline => style::Underline.to_string(),
}
}
}
impl StringAppender for Vec<Style> {
fn append_to_string(&self, string: &mut String) {
for style in self {
string.push_str(&style.to_string());
}
}
}