use crate::style::{Color, Style};
use std::collections::HashMap;
#[derive(Debug, Clone)]
pub struct Theme {
pub primary: Color,
pub secondary: Color,
pub success: Color,
pub warning: Color,
pub error: Color,
pub info: Color,
pub muted: Color,
pub custom: HashMap<String, Color>,
}
impl Theme {
pub fn new() -> Self {
Theme {
primary: Color::Blue,
secondary: Color::Cyan,
success: Color::Green,
warning: Color::Yellow,
error: Color::Red,
info: Color::Cyan,
muted: Color::BrightBlack,
custom: HashMap::new(),
}
}
pub fn default_theme() -> Self {
let mut theme = Theme::new();
theme.primary = Color::BrightBlue;
theme.secondary = Color::Magenta;
theme.success = Color::BrightGreen;
theme.warning = Color::BrightYellow;
theme.error = Color::BrightRed;
theme.info = Color::BrightCyan;
theme.muted = Color::BrightBlack;
theme
}
pub fn monokai() -> Self {
Theme {
primary: Color::rgb(102, 217, 239), secondary: Color::rgb(249, 38, 114), success: Color::rgb(166, 226, 46), warning: Color::rgb(253, 151, 31), error: Color::rgb(249, 38, 114), info: Color::rgb(174, 129, 255), muted: Color::rgb(117, 113, 94), custom: HashMap::new(),
}
}
pub fn night_owl() -> Self {
Theme {
primary: Color::rgb(130, 170, 255), secondary: Color::rgb(199, 146, 234), success: Color::rgb(173, 219, 103), warning: Color::rgb(255, 203, 107), error: Color::rgb(239, 83, 80), info: Color::rgb(128, 203, 196), muted: Color::rgb(99, 119, 119), custom: HashMap::new(),
}
}
pub fn get_style(&self, name: &str) -> Style {
let color = match name {
"primary" => self.primary,
"secondary" => self.secondary,
"success" => self.success,
"warning" => self.warning,
"error" => self.error,
"info" => self.info,
"muted" => self.muted,
_ => self.custom.get(name).copied().unwrap_or(Color::Default),
};
Style::new().foreground(color)
}
pub fn add_color(&mut self, name: impl Into<String>, color: Color) {
self.custom.insert(name.into(), color);
}
}
impl Default for Theme {
fn default() -> Self {
Theme::default_theme()
}
}