use ratatui::style::{Color, Modifier, Style};
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum ThemeName {
Pastel,
}
impl ThemeName {
pub fn all() -> &'static [ThemeName] {
&[ThemeName::Pastel]
}
pub fn as_str(&self) -> &'static str {
match self {
ThemeName::Pastel => "pastel",
}
}
pub fn from_str(s: &str) -> Option<Self> {
match s {
"pastel" => Some(ThemeName::Pastel),
_ => None,
}
}
pub fn next(&self) -> Self {
ThemeName::Pastel
}
}
#[derive(Debug, Clone)]
pub struct Theme {
pub name: ThemeName,
pub background: Color,
pub foreground: Color,
pub accent: Color,
pub success: Color,
pub error: Color,
pub warning: Color,
pub muted: Color,
pub border: Color,
pub highlight: Color,
pub cursor: Color,
pub text_untyped: Color,
pub text_correct: Color,
pub text_incorrect: Color,
pub newline: Color,
pub newline_typed: Color,
}
impl Theme {
pub fn from_name(name: ThemeName) -> Self {
match name {
ThemeName::Pastel => Self::pastel(),
}
}
pub fn pastel() -> Self {
Self {
name: ThemeName::Pastel,
background: Color::Rgb(30, 30, 35),
foreground: Color::Rgb(230, 230, 235),
accent: Color::Rgb(150, 200, 255),
success: Color::Rgb(150, 240, 180),
error: Color::Rgb(255, 150, 150),
warning: Color::Rgb(255, 220, 150),
muted: Color::Rgb(180, 180, 190),
border: Color::Rgb(60, 60, 70),
highlight: Color::Rgb(200, 180, 255),
cursor: Color::Rgb(255, 230, 150),
text_untyped: Color::Rgb(140, 140, 150),
text_correct: Color::Rgb(230, 230, 235),
text_incorrect: Color::Rgb(255, 150, 150),
newline: Color::Rgb(100, 100, 110),
newline_typed: Color::Rgb(160, 160, 170),
}
}
pub fn style(&self, fg: Color) -> Style {
Style::default().fg(fg)
}
pub fn style_accent(&self) -> Style {
self.style(self.accent).add_modifier(Modifier::BOLD)
}
pub fn style_success(&self) -> Style {
self.style(self.success)
}
pub fn style_error(&self) -> Style {
self.style(self.error)
}
pub fn style_muted(&self) -> Style {
self.style(self.muted)
}
pub fn style_highlight(&self) -> Style {
self.style(self.highlight).add_modifier(Modifier::BOLD)
}
}
impl Default for Theme {
fn default() -> Self {
Self::pastel()
}
}