use ratatui::style::{Color, Modifier, Style};
use ratatui::widgets::block::BorderType;
use crate::data::HealthStatus;
#[derive(Debug, Clone)]
pub struct Theme {
pub highlight: Color,
pub warning: Color,
pub critical: Color,
pub healthy: Color,
pub border: Color,
pub header: Style,
pub selected: Style,
pub tab_active: Style,
pub tab_inactive: Style,
pub border_type: BorderType,
}
impl Theme {
pub fn dark() -> Self {
Self {
highlight: Color::Cyan,
warning: Color::Yellow,
critical: Color::Red,
healthy: Color::Green,
border: Color::Gray,
header: Style::default()
.fg(Color::Cyan)
.add_modifier(Modifier::BOLD),
selected: Style::default()
.bg(Color::DarkGray)
.add_modifier(Modifier::BOLD),
tab_active: Style::default()
.fg(Color::Cyan)
.add_modifier(Modifier::BOLD),
tab_inactive: Style::default().fg(Color::Gray),
border_type: BorderType::Rounded,
}
}
pub fn light() -> Self {
Self {
highlight: Color::Blue,
warning: Color::Yellow,
critical: Color::Red,
healthy: Color::Green,
border: Color::DarkGray,
header: Style::default()
.fg(Color::Blue)
.add_modifier(Modifier::BOLD),
selected: Style::default()
.bg(Color::LightBlue)
.add_modifier(Modifier::BOLD),
tab_active: Style::default()
.fg(Color::Blue)
.add_modifier(Modifier::BOLD),
tab_inactive: Style::default().fg(Color::DarkGray),
border_type: BorderType::Rounded,
}
}
pub fn auto_detect() -> Self {
match terminal_light::luma() {
Ok(luma) if luma > 0.5 => Self::light(),
_ => Self::dark(),
}
}
pub fn status_style(&self, status: HealthStatus) -> Style {
match status {
HealthStatus::Healthy => Style::default().fg(self.healthy),
HealthStatus::Warning => Style::default().fg(self.warning),
HealthStatus::Critical => Style::default()
.fg(self.critical)
.add_modifier(Modifier::BOLD),
}
}
}