use ratatui::style::{Color, Modifier, Style};
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
pub enum ThemeKind {
#[default]
Dark,
Light,
}
impl ThemeKind {
pub fn as_str(self) -> &'static str {
match self {
ThemeKind::Dark => "dark",
ThemeKind::Light => "light",
}
}
pub fn from_str(s: &str) -> ThemeKind {
if s.trim().eq_ignore_ascii_case("light") {
ThemeKind::Light
} else {
ThemeKind::Dark
}
}
pub fn label(self) -> &'static str {
match self {
ThemeKind::Dark => "Dark",
ThemeKind::Light => "Light",
}
}
pub fn toggled(self) -> ThemeKind {
match self {
ThemeKind::Dark => ThemeKind::Light,
ThemeKind::Light => ThemeKind::Dark,
}
}
pub fn palette(self) -> Theme {
match self {
ThemeKind::Dark => Theme::dark(),
ThemeKind::Light => Theme::light(),
}
}
}
#[derive(Debug, Clone)]
pub struct Theme {
pub accent: Color,
pub text: Color,
pub text_dim: Color,
pub border: Color,
pub border_focus: Color,
pub success: Color,
pub warn: Color,
pub error: Color,
pub bg_select: Color,
pub unread_badge: Color,
pub encrypted: Color,
}
impl Theme {
pub fn dark() -> Self {
Self {
accent: Color::Rgb(0x4c, 0xc2, 0xff),
text: Color::Rgb(0xf2, 0xf3, 0xf5),
text_dim: Color::Rgb(0x9b, 0xa1, 0xb0),
border: Color::Rgb(0x3a, 0x3f, 0x4c),
border_focus: Color::Rgb(0x4c, 0xc2, 0xff),
success: Color::Rgb(0x4a, 0xde, 0x80),
warn: Color::Rgb(0xfa, 0xcc, 0x15),
error: Color::Rgb(0xff, 0x6b, 0x6b),
bg_select: Color::Rgb(0x26, 0x31, 0x4a),
unread_badge: Color::Rgb(0xfa, 0xcc, 0x15),
encrypted: Color::Rgb(0xc9, 0x8b, 0xff),
}
}
pub fn light() -> Self {
Self {
accent: Color::Rgb(0x03, 0x69, 0xa1),
text: Color::Rgb(0x14, 0x15, 0x1a),
text_dim: Color::Rgb(0x52, 0x55, 0x5e),
border: Color::Rgb(0x8a, 0x90, 0x9c),
border_focus: Color::Rgb(0x03, 0x69, 0xa1),
success: Color::Rgb(0x15, 0x80, 0x3d),
warn: Color::Rgb(0xb4, 0x53, 0x09),
error: Color::Rgb(0xb9, 0x1c, 0x1c),
bg_select: Color::Rgb(0xcf, 0xe4, 0xff),
unread_badge: Color::Rgb(0xb4, 0x53, 0x09),
encrypted: Color::Rgb(0x7e, 0x22, 0xce),
}
}
pub fn accent_bold(&self) -> Style {
Style::default().fg(self.accent).add_modifier(Modifier::BOLD)
}
pub fn text_style(&self) -> Style {
Style::default().fg(self.text)
}
pub fn dim(&self) -> Style {
Style::default().fg(self.text_dim)
}
pub fn ok(&self) -> Style {
Style::default().fg(self.success).add_modifier(Modifier::BOLD)
}
pub fn warn_style(&self) -> Style {
Style::default().fg(self.warn).add_modifier(Modifier::BOLD)
}
pub fn err_style(&self) -> Style {
Style::default().fg(self.error).add_modifier(Modifier::BOLD)
}
pub fn unread(&self) -> Style {
Style::default()
.fg(self.unread_badge)
.add_modifier(Modifier::BOLD)
}
pub fn enc(&self) -> Style {
Style::default()
.fg(self.encrypted)
.add_modifier(Modifier::BOLD)
}
pub fn select_bg(&self) -> Style {
Style::default().bg(self.bg_select).fg(self.text)
}
pub fn select_bg_focus(&self) -> Style {
Style::default()
.bg(self.bg_select)
.fg(self.accent)
.add_modifier(Modifier::BOLD)
}
pub fn border_style(&self) -> Style {
Style::default().fg(self.border)
}
pub fn border_focus_style(&self) -> Style {
Style::default()
.fg(self.border_focus)
.add_modifier(Modifier::BOLD)
}
}