use std::collections::HashMap;
use ratatui::style::Style;
use crate::TcaTheme;
#[derive(Debug, Clone)]
pub struct StyleSet {
pub name: String,
pub author: String,
pub is_dark: bool,
pub primary: Style,
pub secondary: Style,
pub muted: Style,
pub border: Style,
pub border_muted: Style,
pub selection: Style,
pub cursor: Style,
pub cursor_muted: Style,
pub error: Style,
pub warning: Style,
pub info: Style,
pub success: Style,
pub highlight: Style,
pub link: Style,
custom: HashMap<String, Style>,
}
impl StyleSet {
#[cfg(feature = "fs")]
pub fn from_name(name: &str) -> Self {
TcaTheme::from_name(name).into()
}
#[cfg(feature = "fs")]
pub fn from_default_light_cfg() -> Self {
TcaTheme::from_default_light_cfg().into()
}
pub fn insert_custom(&mut self, key: impl Into<String>, style: Style) {
self.custom.insert(key.into(), style);
}
pub fn get_custom(&self, key: &str) -> Option<&Style> {
self.custom.get(key)
}
}
impl From<TcaTheme> for StyleSet {
fn from(value: TcaTheme) -> Self {
StyleSet {
name: value.meta.name.clone(),
author: value.meta.author.clone(),
is_dark: value.meta.dark,
primary: Style::default()
.bg(value.ui.bg_primary)
.fg(value.ui.fg_primary),
secondary: Style::default()
.bg(value.ui.bg_secondary)
.fg(value.ui.fg_secondary),
muted: Style::default()
.bg(value.ui.bg_primary)
.fg(value.ui.fg_muted),
border: Style::default()
.bg(value.ui.bg_primary)
.fg(value.ui.border_primary),
border_muted: Style::default()
.bg(value.ui.bg_primary)
.fg(value.ui.border_muted),
selection: Style::default()
.bg(value.ui.selection_bg)
.fg(value.ui.selection_fg),
cursor: Style::default()
.bg(value.ui.bg_primary)
.fg(value.ui.cursor_primary),
cursor_muted: Style::default()
.bg(value.ui.bg_primary)
.fg(value.ui.cursor_muted),
error: Style::default()
.bg(value.ui.bg_primary)
.fg(value.semantic.error),
warning: Style::default()
.bg(value.ui.bg_primary)
.fg(value.semantic.warning),
info: Style::default()
.bg(value.ui.bg_primary)
.fg(value.semantic.info),
success: Style::default()
.bg(value.ui.bg_primary)
.fg(value.semantic.success),
highlight: Style::default()
.bg(value.ui.bg_primary)
.fg(value.semantic.highlight),
link: Style::default()
.bg(value.ui.bg_primary)
.fg(value.semantic.link),
custom: HashMap::default(),
}
}
}
impl From<&TcaTheme> for StyleSet {
fn from(value: &TcaTheme) -> Self {
value.clone().into()
}
}
#[cfg(feature = "fs")]
impl Default for StyleSet {
fn default() -> Self {
TcaTheme::default().into()
}
}
#[cfg(feature = "fs")]
#[derive(Debug)]
pub struct StyleSetCursor(crate::theme::TcaThemeCursor);
#[cfg(feature = "fs")]
impl StyleSetCursor {
pub fn new(themes: impl IntoIterator<Item = TcaTheme>) -> Self {
Self(crate::theme::TcaThemeCursor::new(themes))
}
pub fn with_builtins() -> Self {
Self(crate::theme::TcaThemeCursor::with_builtins())
}
pub fn with_user_themes() -> Self {
Self(crate::theme::TcaThemeCursor::with_user_themes())
}
pub fn with_all_themes() -> Self {
Self(crate::theme::TcaThemeCursor::with_all_themes())
}
pub fn peek(&self) -> Option<StyleSet> {
self.0.peek().map(Into::into)
}
#[allow(clippy::should_implement_trait)]
pub fn next(&mut self) -> Option<StyleSet> {
self.0.next().map(Into::into)
}
pub fn prev(&mut self) -> Option<StyleSet> {
self.0.prev().map(Into::into)
}
pub fn set_current(&mut self, name: &str) -> Option<StyleSet> {
self.0.set_current(name).map(Into::into)
}
pub fn len(&self) -> usize {
self.0.len()
}
pub fn is_empty(&self) -> bool {
self.0.is_empty()
}
}