use ratatui::style::{Color, Modifier, Style};
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct Theme {
pub ok: Color,
pub error: Color,
pub warning: Color,
pub new: Color,
pub modified: Color,
pub secret: Color,
pub selected: Color,
pub dim: Color,
pub accent: Color,
}
impl Theme {
#[must_use]
pub const fn dark() -> Self {
Self {
ok: Color::Green,
error: Color::Red,
warning: Color::Yellow,
new: Color::Cyan,
modified: Color::Magenta,
secret: Color::DarkGray,
selected: Color::Indexed(238),
dim: Color::Gray,
accent: Color::Blue,
}
}
#[must_use]
pub const fn header(&self) -> Style {
Style::new().fg(self.accent).add_modifier(Modifier::BOLD)
}
#[must_use]
pub const fn selected_row(&self) -> Style {
Style::new().bg(self.selected).add_modifier(Modifier::BOLD)
}
#[must_use]
pub const fn secret_cell(&self) -> Style {
Style::new().fg(self.secret).add_modifier(Modifier::DIM)
}
#[must_use]
pub const fn dim_cell(&self) -> Style {
Style::new().fg(self.dim)
}
#[must_use]
pub const fn error_toast(&self) -> Style {
Style::new().fg(self.error).add_modifier(Modifier::BOLD)
}
#[must_use]
pub const fn info_toast(&self) -> Style {
Style::new().fg(self.ok)
}
}
impl Default for Theme {
fn default() -> Self {
Self::dark()
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn default_equals_dark() {
assert_eq!(Theme::default(), Theme::dark());
}
#[test]
fn dark_palette_distinguishes_ok_from_error() {
let t = Theme::dark();
assert_ne!(t.ok, t.error);
assert_ne!(t.warning, t.error);
}
}