use std::path::Path;
use crate::errors::ConfigResult;
use super::theme::Theme;
#[derive(Debug, Clone)]
pub struct ThemeRegistry {
themes: Vec<Theme>,
}
impl ThemeRegistry {
pub fn load(user_dir: Option<&Path>) -> ConfigResult<Self> {
let themes = Theme::load_all(user_dir)?;
Ok(Self { themes })
}
pub fn names(&self) -> Vec<String> {
self.themes.iter().map(|t| t.name.clone()).collect()
}
pub fn len(&self) -> usize {
self.themes.len()
}
pub fn is_empty(&self) -> bool {
self.themes.is_empty()
}
pub fn resolve(&self, index: usize) -> Theme {
self.themes
.get(index)
.cloned()
.unwrap_or_else(Theme::fallback)
}
pub fn get(&self, index: usize) -> Option<&Theme> {
self.themes.get(index)
}
#[must_use]
pub fn without_colors(self) -> Self {
Self {
themes: self.themes.iter().map(Theme::without_colors).collect(),
}
}
}