use std::fmt::Write;
use crate::theme_color::ThemeColor;
#[derive(Clone, Debug, Default, PartialEq, Eq)]
pub struct ThemeColors {
pub bg: ThemeColor,
pub fg: ThemeColor,
pub caret: ThemeColor,
pub selection: ThemeColor,
pub selection_focused: ThemeColor,
pub selection_match: ThemeColor,
pub selection_match_main: ThemeColor,
pub gutter_bg: ThemeColor,
pub gutter_fg: ThemeColor,
pub highlight_space: ThemeColor,
pub active_line: ThemeColor,
pub active_line_gutter_bg: ThemeColor,
pub border: ThemeColor,
pub tooltip_bg: ThemeColor,
pub tooltip_fg: ThemeColor,
pub tooltip_selected_bg: ThemeColor,
pub tooltip_selected_fg: ThemeColor,
pub tooltip_info_bg: ThemeColor,
pub syntax_keyword: ThemeColor,
pub syntax_string: ThemeColor,
pub syntax_comment: ThemeColor,
pub syntax_number: ThemeColor,
pub syntax_function: ThemeColor,
pub syntax_type: ThemeColor,
pub syntax_constant: ThemeColor,
pub syntax_operator: ThemeColor,
pub syntax_property: ThemeColor,
pub syntax_heading: ThemeColor,
pub syntax_link: ThemeColor,
pub syntax_invalid: ThemeColor,
}
impl ThemeColors {
fn entries(&self) -> [(&'static str, &ThemeColor); 30] {
[
("bg", &self.bg),
("fg", &self.fg),
("caret", &self.caret),
("selection", &self.selection),
("selection-focused", &self.selection_focused),
("selection-match", &self.selection_match),
("selection-match-main", &self.selection_match_main),
("gutter-bg", &self.gutter_bg),
("gutter-fg", &self.gutter_fg),
("highlight-space", &self.highlight_space),
("active-line", &self.active_line),
("active-line-gutter-bg", &self.active_line_gutter_bg),
("border", &self.border),
("tooltip-bg", &self.tooltip_bg),
("tooltip-fg", &self.tooltip_fg),
("tooltip-selected-bg", &self.tooltip_selected_bg),
("tooltip-selected-fg", &self.tooltip_selected_fg),
("tooltip-info-bg", &self.tooltip_info_bg),
("syntax-keyword", &self.syntax_keyword),
("syntax-string", &self.syntax_string),
("syntax-comment", &self.syntax_comment),
("syntax-number", &self.syntax_number),
("syntax-function", &self.syntax_function),
("syntax-type", &self.syntax_type),
("syntax-constant", &self.syntax_constant),
("syntax-operator", &self.syntax_operator),
("syntax-property", &self.syntax_property),
("syntax-heading", &self.syntax_heading),
("syntax-link", &self.syntax_link),
("syntax-invalid", &self.syntax_invalid),
]
}
pub fn style_attr(&self) -> Option<String> {
let mut style = String::new();
for (name, theme_color) in self.entries() {
if let Some(light) = theme_color.light.as_deref() {
let _ = write!(style, "--dxcm-light-{name}: {light}; ");
}
if let Some(dark) = theme_color.dark.as_deref() {
let _ = write!(style, "--dxcm-dark-{name}: {dark}; ");
}
}
let style = style.trim_end().to_string();
(!style.is_empty()).then_some(style)
}
}