use crate::widgets::markdown_preview::services::theme::ThemeVariant;
use ratatui::style::Color;
use crate::widgets::markdown_preview::services::theme::diff_colors::DiffColors;
use crate::widgets::markdown_preview::services::theme::markdown_colors::MarkdownColors;
use crate::widgets::markdown_preview::services::theme::syntax_colors::SyntaxColors;
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct AppTheme {
pub primary: Color,
pub secondary: Color,
pub accent: Color,
pub error: Color,
pub warning: Color,
pub success: Color,
pub info: Color,
pub text: Color,
pub text_muted: Color,
pub selected_text: Color,
pub background: Color,
pub background_panel: Color,
pub background_element: Color,
pub background_menu: Color,
pub border: Color,
pub border_active: Color,
pub border_subtle: Color,
pub diff: DiffColors,
pub markdown: MarkdownColors,
pub syntax: SyntaxColors,
}
use std::path::Path;
use crate::widgets::markdown_preview::services::theme::loader::{load_theme_file, load_theme_str};
impl AppTheme {
pub fn from_json(json: &str, variant: ThemeVariant) -> Result<Self, String> {
load_theme_str(json, variant)
}
pub fn from_json_file<P: AsRef<Path>>(path: P, variant: ThemeVariant) -> Result<Self, String> {
load_theme_file(path, variant)
}
}
impl AppTheme {
#[allow(clippy::too_many_arguments)]
pub fn new(
primary: Color,
secondary: Color,
accent: Color,
error: Color,
warning: Color,
success: Color,
info: Color,
text: Color,
text_muted: Color,
selected_text: Color,
background: Color,
background_panel: Color,
background_element: Color,
background_menu: Color,
border: Color,
border_active: Color,
border_subtle: Color,
diff: DiffColors,
markdown: MarkdownColors,
syntax: SyntaxColors,
) -> Self {
Self {
primary,
secondary,
accent,
error,
warning,
success,
info,
text,
text_muted,
selected_text,
background,
background_panel,
background_element,
background_menu,
border,
border_active,
border_subtle,
diff,
markdown,
syntax,
}
}
}
impl AppTheme {
pub fn get_color(&self, name: &str) -> Option<Color> {
match name {
"primary" => Some(self.primary),
"secondary" => Some(self.secondary),
"accent" => Some(self.accent),
"error" => Some(self.error),
"warning" => Some(self.warning),
"success" => Some(self.success),
"info" => Some(self.info),
"text" => Some(self.text),
"text_muted" | "textMuted" => Some(self.text_muted),
"selected_text" | "selectedText" => Some(self.selected_text),
"background" => Some(self.background),
"background_panel" | "backgroundPanel" => Some(self.background_panel),
"background_element" | "backgroundElement" => Some(self.background_element),
"background_menu" | "backgroundMenu" => Some(self.background_menu),
"border" => Some(self.border),
"border_active" | "borderActive" => Some(self.border_active),
"border_subtle" | "borderSubtle" => Some(self.border_subtle),
_ => None,
}
}
}
impl Default for AppTheme {
fn default() -> Self {
Self {
primary: Color::Rgb(131, 165, 152), secondary: Color::Rgb(211, 134, 155), accent: Color::Rgb(142, 192, 124), error: Color::Rgb(251, 73, 52), warning: Color::Rgb(254, 128, 25), success: Color::Rgb(184, 187, 38), info: Color::Rgb(250, 189, 47),
text: Color::Rgb(235, 219, 178), text_muted: Color::Rgb(146, 131, 116), selected_text: Color::Rgb(251, 241, 199),
background: Color::Rgb(40, 40, 40), background_panel: Color::Rgb(60, 56, 54), background_element: Color::Rgb(80, 73, 69), background_menu: Color::Rgb(60, 56, 54),
border: Color::Rgb(102, 92, 84), border_active: Color::Rgb(235, 219, 178), border_subtle: Color::Rgb(80, 73, 69),
diff: DiffColors::default(),
markdown: MarkdownColors::default(),
syntax: SyntaxColors::default(),
}
}
}