vtcode_ui/theme/registry/
suites.rs1use super::*;
2
3pub(crate) fn theme_definition(theme_id: &str) -> Option<&'static ThemeDefinition> {
4 REGISTRY.get(theme_id)
5}
6
7pub(crate) fn all_theme_definitions() -> &'static HashMap<&'static str, ThemeDefinition> {
8 ®ISTRY
9}
10
11pub fn available_themes() -> Vec<&'static str> {
13 let mut keys: Vec<_> = REGISTRY.keys().copied().collect();
14 keys.sort();
15 keys
16}
17
18pub fn theme_label(theme_id: &str) -> Option<&'static str> {
20 theme_definition(theme_id).map(|definition| definition.label)
21}
22
23fn suite_id_for_theme(theme_id: &str) -> Option<&'static str> {
24 for set in GpuiKitThemeSet::ALL {
28 if set.member_ids().contains(&theme_id) {
29 return Some(set.suite_id());
30 }
31 }
32 match theme_id {
33 "nord" => Some("nord"),
34 "mono" => Some("mono"),
35 _ => None,
36 }
37}
38
39fn suite_label(suite_id: &str) -> Option<&'static str> {
40 let fixed = match suite_id {
41 "mono" => Some("Mono"),
42 "nord" => Some("Nord"),
43 _ => None,
44 };
45 fixed.or_else(|| {
46 GpuiKitThemeSet::ALL
47 .iter()
48 .find(|set| set.suite_id() == suite_id)
49 .map(|set| set.label())
50 })
51}
52
53pub fn theme_suite_id(theme_id: &str) -> Option<&'static str> {
55 suite_id_for_theme(theme_id)
56}
57
58pub fn theme_suite_label(theme_id: &str) -> Option<&'static str> {
60 suite_id_for_theme(theme_id).and_then(suite_label)
61}
62
63enum GpuiKitThemeSet {
69 Ciapre,
70 Vitesse,
71 Catppuccin,
72 GpuiKit {
73 suite_id: &'static str,
74 label: &'static str,
75 ids: &'static [&'static str],
76 },
77}
78
79impl GpuiKitThemeSet {
80 const ALL: &'static [Self] = &[
81 Self::Ciapre,
82 Self::Vitesse,
83 Self::Catppuccin,
84 Self::GpuiKit {
85 suite_id: "adventure",
86 label: "Adventure",
87 ids: &["adventure", "adventure-time"],
88 },
89 Self::GpuiKit {
90 suite_id: "ayu",
91 label: "Ayu",
92 ids: &["ayu-dark", "ayu-light"],
93 },
94 Self::GpuiKit {
95 suite_id: "everforest",
96 label: "Everforest",
97 ids: &["everforest-dark", "everforest-light"],
98 },
99 Self::GpuiKit {
100 suite_id: "flexoki",
101 label: "Flexoki",
102 ids: &["flexoki-dark", "flexoki-light"],
103 },
104 Self::GpuiKit {
105 suite_id: "gruvbox",
106 label: "Gruvbox",
107 ids: &[
108 "gruvbox-dark",
109 "gruvbox-dark-hard",
110 "gruvbox-light",
111 "gruvbox-light-hard",
112 "gruvbox-material",
113 "gruvbox-material-dark",
114 "gruvbox-material-light",
115 ],
116 },
117 Self::GpuiKit {
118 suite_id: "hybrid",
119 label: "Hybrid",
120 ids: &["hybrid-dark", "hybrid-light"],
121 },
122 Self::GpuiKit {
123 suite_id: "macos-classic",
124 label: "macOS Classic",
125 ids: &["macos-classic-dark", "macos-classic-light"],
126 },
127 Self::GpuiKit {
128 suite_id: "mellifluous",
129 label: "Mellifluous",
130 ids: &["mellifluous-dark", "mellifluous-light"],
131 },
132 Self::GpuiKit {
133 suite_id: "molokai",
134 label: "Molokai",
135 ids: &["molokai-dark", "molokai-light"],
136 },
137 Self::GpuiKit {
138 suite_id: "solarized",
139 label: "Solarized",
140 ids: &["solarized-dark", "solarized-dark-hc", "solarized-light"],
141 },
142 Self::GpuiKit {
143 suite_id: "tokyo-night",
144 label: "Tokyo Night",
145 ids: &["tokyo-moon", "tokyo-night", "tokyo-storm"],
146 },
147 ];
148
149 fn suite_id(&self) -> &'static str {
150 match self {
151 Self::Ciapre => "ciapre",
152 Self::Vitesse => "vitesse",
153 Self::Catppuccin => "catppuccin",
154 Self::GpuiKit { suite_id, .. } => suite_id,
155 }
156 }
157
158 fn label(&self) -> &'static str {
159 match self {
160 Self::Ciapre => "Ciapre",
161 Self::Vitesse => "Vitesse",
162 Self::Catppuccin => "Catppuccin",
163 Self::GpuiKit { label, .. } => label,
164 }
165 }
166
167 fn member_ids(&self) -> &'static [&'static str] {
168 match self {
169 Self::Ciapre => &["ciapre", "ciapre-blue", "ciapre-dark", "noir"],
170 Self::Vitesse => &[
171 "vitesse-black",
172 "vitesse-dark",
173 "vitesse-dark-soft",
174 "vitesse-light",
175 "vitesse-light-soft",
176 ],
177 Self::Catppuccin => &[
178 "catppuccin-frappe",
179 "catppuccin-latte",
180 "catppuccin-macchiato",
181 "catppuccin-mocha",
182 ],
183 Self::GpuiKit { ids, .. } => ids,
184 }
185 }
186}
187
188pub fn available_theme_suites() -> Vec<ThemeSuite> {
190 const ORDER: &[&str] = &[
191 "ciapre",
192 "vitesse",
193 "catppuccin",
194 "adventure",
195 "ayu",
196 "everforest",
197 "flexoki",
198 "gruvbox",
199 "hybrid",
200 "macos-classic",
201 "mellifluous",
202 "molokai",
203 "solarized",
204 "tokyo-night",
205 "mono",
206 "nord",
207 ];
208
209 ORDER
210 .iter()
211 .filter_map(|suite_id| {
212 let mut theme_ids: Vec<&'static str> = available_themes()
213 .into_iter()
214 .filter(|theme_id| suite_id_for_theme(theme_id) == Some(*suite_id))
215 .collect();
216 if theme_ids.is_empty() {
217 return None;
218 }
219 theme_ids.sort_unstable();
220 Some(ThemeSuite {
221 id: suite_id,
222 label: suite_label(suite_id)?,
223 theme_ids,
224 })
225 })
226 .collect()
227}