use ratatui::style::{Color, Modifier, Style};
pub struct Theme {
pub primary: Color, pub secondary: Color, pub success: Color, pub warning: Color, pub error: Color, pub text: Color,
pub subtle: Color,
pub border: Color,
pub bg: Color,
pub surface: Color, pub highlight: Color, pub focused_border: Color,
pub progress_bar: Color, pub sparkline: Color, }
impl Theme {
pub fn dark() -> Self {
Self {
primary: Color::Rgb(196, 248, 245), secondary: Color::Rgb(44, 82, 77), success: Color::Rgb(181, 182, 184), warning: Color::Rgb(150, 186, 220), error: Color::Rgb(163, 173, 171), text: Color::Rgb(196, 248, 245), subtle: Color::Rgb(142, 173, 202), border: Color::Rgb(79, 137, 139), bg: Color::Reset, surface: Color::Reset, highlight: Color::Rgb(28, 27, 27), focused_border: Color::Rgb(196, 248, 245),
progress_bar: Color::Rgb(44, 82, 77),
sparkline: Color::Rgb(196, 248, 245),
}
}
pub fn light() -> Self {
Self {
primary: Color::Rgb(214, 48, 49),
secondary: Color::Rgb(0, 149, 200),
success: Color::Rgb(0, 184, 148),
warning: Color::Rgb(225, 112, 0),
error: Color::Rgb(214, 48, 49),
text: Color::Rgb(20, 20, 30),
subtle: Color::Rgb(120, 120, 140),
border: Color::Rgb(200, 200, 220),
bg: Color::Rgb(250, 250, 255),
surface: Color::Rgb(240, 240, 250),
highlight: Color::Rgb(230, 220, 245),
focused_border: Color::Rgb(214, 48, 49),
progress_bar: Color::Rgb(0, 149, 200),
sparkline: Color::Rgb(214, 48, 49),
}
}
pub fn detect_dark_mode() -> bool {
if let Ok(val) = std::env::var("COLORFGBG") {
if let Some(parts) = val.rsplit_once(';') {
if let Ok(bg) = parts.1.parse::<i32>() {
return !(7..234).contains(&bg);
}
}
}
if let Ok(val) = std::env::var("COLORTERM") {
if val.contains("dark") {
return true;
}
}
true
}
pub fn panel_style(&self) -> Style {
Style::default().fg(self.text).bg(self.surface)
}
pub fn title_style(&self) -> Style {
Style::default()
.fg(self.primary)
.add_modifier(Modifier::BOLD)
}
pub fn value_style(&self) -> Style {
Style::default()
.fg(self.secondary)
.add_modifier(Modifier::BOLD)
}
pub fn error_style(&self) -> Style {
Style::default().fg(self.error).add_modifier(Modifier::BOLD)
}
pub fn warning_style(&self) -> Style {
Style::default().fg(self.warning)
}
pub fn subtle_style(&self) -> Style {
Style::default().fg(self.subtle)
}
pub fn success_style(&self) -> Style {
Style::default()
.fg(self.success)
.add_modifier(Modifier::BOLD)
}
pub fn tab_active_style(&self) -> Style {
Style::default()
.fg(self.bg)
.bg(self.primary)
.add_modifier(Modifier::BOLD)
}
pub fn tab_inactive_style(&self) -> Style {
Style::default().fg(self.subtle).bg(self.surface)
}
pub fn focused_field_style(&self) -> Style {
Style::default()
.fg(self.bg)
.bg(self.primary)
.add_modifier(Modifier::BOLD)
}
pub fn normal_field_style(&self) -> Style {
Style::default().fg(self.text).bg(self.surface)
}
pub fn focused_border_style(&self) -> Style {
Style::default().fg(self.focused_border)
}
pub fn border_style(&self) -> Style {
Style::default().fg(self.border)
}
pub fn key_hint(&self, key: &str, desc: &str) -> String {
format!("[{}] {}", key, desc)
}
}
impl Default for Theme {
fn default() -> Self {
if Self::detect_dark_mode() {
Self::dark()
} else {
Self::light()
}
}
}