1use crate::{themes, Theme, ThemeMetadata};
2use anyhow::{anyhow, Result};
3use gpui2::SharedString;
4use std::{collections::HashMap, sync::Arc};
5
6pub struct ThemeRegistry {
7 themes: HashMap<SharedString, Arc<Theme>>,
8}
9
10impl ThemeRegistry {
11 fn insert_themes(&mut self, themes: impl IntoIterator<Item = Theme>) {
12 for theme in themes.into_iter() {
13 self.themes
14 .insert(theme.metadata.name.clone(), Arc::new(theme));
15 }
16 }
17
18 pub fn list_names(&self, _staff: bool) -> impl Iterator<Item = SharedString> + '_ {
19 self.themes.keys().cloned()
20 }
21
22 pub fn list(&self, _staff: bool) -> impl Iterator<Item = ThemeMetadata> + '_ {
23 self.themes.values().map(|theme| theme.metadata.clone())
24 }
25
26 pub fn get(&self, name: &str) -> Result<Arc<Theme>> {
27 self.themes
28 .get(name)
29 .ok_or_else(|| anyhow!("theme not found: {}", name))
30 .cloned()
31 }
32}
33
34impl Default for ThemeRegistry {
35 fn default() -> Self {
36 let mut this = Self {
37 themes: HashMap::default(),
38 };
39
40 this.insert_themes([
41 themes::andromeda(),
42 themes::atelier_cave_dark(),
43 themes::atelier_cave_light(),
44 themes::atelier_dune_dark(),
45 themes::atelier_dune_light(),
46 themes::atelier_estuary_dark(),
47 themes::atelier_estuary_light(),
48 themes::atelier_forest_dark(),
49 themes::atelier_forest_light(),
50 themes::atelier_heath_dark(),
51 themes::atelier_heath_light(),
52 themes::atelier_lakeside_dark(),
53 themes::atelier_lakeside_light(),
54 themes::atelier_plateau_dark(),
55 themes::atelier_plateau_light(),
56 themes::atelier_savanna_dark(),
57 themes::atelier_savanna_light(),
58 themes::atelier_seaside_dark(),
59 themes::atelier_seaside_light(),
60 themes::atelier_sulphurpool_dark(),
61 themes::atelier_sulphurpool_light(),
62 themes::ayu_dark(),
63 themes::ayu_light(),
64 themes::ayu_mirage(),
65 themes::gruvbox_dark(),
66 themes::gruvbox_dark_hard(),
67 themes::gruvbox_dark_soft(),
68 themes::gruvbox_light(),
69 themes::gruvbox_light_hard(),
70 themes::gruvbox_light_soft(),
71 themes::one_dark(),
72 themes::one_light(),
73 themes::rose_pine(),
74 themes::rose_pine_dawn(),
75 themes::rose_pine_moon(),
76 themes::sandcastle(),
77 themes::solarized_dark(),
78 themes::solarized_light(),
79 themes::summercamp(),
80 ]);
81
82 this
83 }
84}