Skip to main content

hue/
catalog.rs

1use std::collections::BTreeMap;
2use std::fs;
3
4use serde::{Deserialize, Serialize};
5
6use crate::config::Paths;
7use crate::error::Result;
8
9#[derive(Clone, Debug, Default, Serialize, Deserialize, PartialEq, Eq)]
10pub struct ThemeMapping {
11    #[serde(default)]
12    pub ghostty: Option<String>,
13    #[serde(default)]
14    pub zed: Option<String>,
15}
16
17pub type ThemeCatalog = BTreeMap<String, ThemeMapping>;
18
19const THEME_CATALOG: &str = include_str!("../themes.toml");
20
21pub fn init_catalog(paths: &Paths) -> Result<()> {
22    fs::create_dir_all(&paths.root)?;
23
24    if !paths.catalog.exists() {
25        fs::write(&paths.catalog, THEME_CATALOG)?;
26    }
27
28    Ok(())
29}
30
31pub fn load_catalog(paths: &Paths) -> Result<ThemeCatalog> {
32    init_catalog(paths)?;
33
34    let contents = fs::read_to_string(&paths.catalog)?;
35
36    Ok(toml::from_str(&contents)?)
37}