1mod theme_registry;
2
3use gpui::{
4 color::Color,
5 elements::{ContainerStyle, ImageStyle, LabelStyle},
6 fonts::{HighlightStyle, TextStyle},
7 Border,
8};
9use serde::Deserialize;
10use std::{collections::HashMap, sync::Arc};
11
12pub use theme_registry::*;
13
14pub const DEFAULT_THEME_NAME: &'static str = "dark";
15
16#[derive(Deserialize, Default)]
17pub struct Theme {
18 #[serde(default)]
19 pub name: String,
20 pub workspace: Workspace,
21 pub chat_panel: ChatPanel,
22 pub contacts_panel: ContactsPanel,
23 pub project_panel: ProjectPanel,
24 pub command_palette: CommandPalette,
25 pub selector: Selector,
26 pub editor: Editor,
27 pub search: Search,
28 pub project_diagnostics: ProjectDiagnostics,
29 pub breadcrumbs: ContainedText,
30}
31
32#[derive(Deserialize, Default)]
33pub struct Workspace {
34 pub background: Color,
35 pub titlebar: Titlebar,
36 pub tab: Tab,
37 pub active_tab: Tab,
38 pub pane_divider: Border,
39 pub leader_border_opacity: f32,
40 pub leader_border_width: f32,
41 pub sidebar_resize_handle: ContainerStyle,
42 pub status_bar: StatusBar,
43 pub toolbar: Toolbar,
44 pub disconnected_overlay: ContainedText,
45 pub modal: ContainerStyle,
46}
47
48#[derive(Clone, Deserialize, Default)]
49pub struct Titlebar {
50 #[serde(flatten)]
51 pub container: ContainerStyle,
52 pub height: f32,
53 pub title: TextStyle,
54 pub avatar_width: f32,
55 pub avatar_ribbon: AvatarRibbon,
56 pub offline_icon: OfflineIcon,
57 pub share_icon: ShareIcon,
58 pub hovered_share_icon: ShareIcon,
59 pub active_share_icon: ShareIcon,
60 pub hovered_active_share_icon: ShareIcon,
61 pub avatar: ImageStyle,
62 pub sign_in_prompt: ContainedText,
63 pub hovered_sign_in_prompt: ContainedText,
64 pub outdated_warning: ContainedText,
65}
66
67#[derive(Clone, Deserialize, Default)]
68pub struct AvatarRibbon {
69 #[serde(flatten)]
70 pub container: ContainerStyle,
71 pub width: f32,
72 pub height: f32,
73}
74
75#[derive(Clone, Deserialize, Default)]
76pub struct OfflineIcon {
77 #[serde(flatten)]
78 pub container: ContainerStyle,
79 pub width: f32,
80 pub color: Color,
81}
82
83#[derive(Clone, Deserialize, Default)]
84pub struct ShareIcon {
85 #[serde(flatten)]
86 pub container: ContainerStyle,
87 pub color: Color,
88}
89
90#[derive(Clone, Deserialize, Default)]
91pub struct Tab {
92 pub height: f32,
93 #[serde(flatten)]
94 pub container: ContainerStyle,
95 #[serde(flatten)]
96 pub label: LabelStyle,
97 pub spacing: f32,
98 pub icon_width: f32,
99 pub icon_close: Color,
100 pub icon_close_active: Color,
101 pub icon_dirty: Color,
102 pub icon_conflict: Color,
103}
104
105#[derive(Clone, Deserialize, Default)]
106pub struct Toolbar {
107 #[serde(flatten)]
108 pub container: ContainerStyle,
109 pub height: f32,
110 pub item_spacing: f32,
111}
112
113#[derive(Clone, Deserialize, Default)]
114pub struct Search {
115 #[serde(flatten)]
116 pub container: ContainerStyle,
117 pub editor: FindEditor,
118 pub invalid_editor: ContainerStyle,
119 pub option_button_group: ContainerStyle,
120 pub option_button: ContainedText,
121 pub active_option_button: ContainedText,
122 pub hovered_option_button: ContainedText,
123 pub active_hovered_option_button: ContainedText,
124 pub match_background: Color,
125 pub match_index: ContainedText,
126 pub results_status: TextStyle,
127 pub tab_icon_width: f32,
128 pub tab_icon_spacing: f32,
129}
130
131#[derive(Clone, Deserialize, Default)]
132pub struct FindEditor {
133 #[serde(flatten)]
134 pub input: FieldEditor,
135 pub min_width: f32,
136 pub max_width: f32,
137}
138
139#[derive(Deserialize, Default)]
140pub struct StatusBar {
141 #[serde(flatten)]
142 pub container: ContainerStyle,
143 pub height: f32,
144 pub item_spacing: f32,
145 pub cursor_position: TextStyle,
146 pub diagnostic_message: TextStyle,
147 pub lsp_message: TextStyle,
148 pub auto_update_progress_message: TextStyle,
149 pub auto_update_done_message: TextStyle,
150 pub sidebar_buttons: StatusBarSidebarButtons,
151 pub diagnostics: StatusBarDiagnostics,
152}
153
154#[derive(Deserialize, Default)]
155pub struct StatusBarSidebarButtons {
156 pub group_left: ContainerStyle,
157 pub group_right: ContainerStyle,
158 pub item: SidebarItem,
159 pub item_active: SidebarItem,
160 pub item_hover: SidebarItem,
161}
162
163#[derive(Deserialize, Default)]
164pub struct StatusBarDiagnostics {
165 pub message: ContainedText,
166 pub summary_ok: ContainedText,
167 pub summary_ok_hover: ContainedText,
168 pub summary_warning: ContainedText,
169 pub summary_warning_hover: ContainedText,
170 pub summary_error: ContainedText,
171 pub summary_error_hover: ContainedText,
172 pub icon_color_ok: Color,
173 pub icon_color_error: Color,
174 pub icon_color_warning: Color,
175 pub height: f32,
176 pub icon_width: f32,
177 pub icon_spacing: f32,
178 pub summary_spacing: f32,
179}
180
181#[derive(Deserialize, Default)]
182pub struct Sidebar {
183 pub resize_handle: ContainerStyle,
184}
185
186#[derive(Clone, Copy, Deserialize, Default)]
187pub struct SidebarItem {
188 #[serde(flatten)]
189 pub container: ContainerStyle,
190 pub icon_color: Color,
191 pub icon_size: f32,
192}
193
194#[derive(Deserialize, Default)]
195pub struct ChatPanel {
196 #[serde(flatten)]
197 pub container: ContainerStyle,
198 pub message: ChatMessage,
199 pub pending_message: ChatMessage,
200 pub channel_select: ChannelSelect,
201 pub input_editor: FieldEditor,
202 pub sign_in_prompt: TextStyle,
203 pub hovered_sign_in_prompt: TextStyle,
204}
205
206#[derive(Debug, Deserialize, Default)]
207pub struct ProjectPanel {
208 #[serde(flatten)]
209 pub container: ContainerStyle,
210 pub entry: ProjectPanelEntry,
211 pub hovered_entry: ProjectPanelEntry,
212 pub selected_entry: ProjectPanelEntry,
213 pub hovered_selected_entry: ProjectPanelEntry,
214}
215
216#[derive(Debug, Deserialize, Default)]
217pub struct ProjectPanelEntry {
218 pub height: f32,
219 #[serde(flatten)]
220 pub container: ContainerStyle,
221 pub text: TextStyle,
222 pub icon_color: Color,
223 pub icon_size: f32,
224 pub icon_spacing: f32,
225}
226
227#[derive(Debug, Deserialize, Default)]
228pub struct CommandPalette {
229 pub key: ContainedLabel,
230 pub keystroke_spacing: f32,
231}
232
233#[derive(Deserialize, Default)]
234pub struct ContactsPanel {
235 #[serde(flatten)]
236 pub container: ContainerStyle,
237 pub host_row_height: f32,
238 pub host_avatar: ImageStyle,
239 pub host_username: ContainedText,
240 pub tree_branch_width: f32,
241 pub tree_branch_color: Color,
242 pub shared_project: WorktreeRow,
243 pub hovered_shared_project: WorktreeRow,
244 pub unshared_project: WorktreeRow,
245 pub hovered_unshared_project: WorktreeRow,
246}
247
248#[derive(Deserialize, Default)]
249pub struct WorktreeRow {
250 #[serde(flatten)]
251 pub container: ContainerStyle,
252 pub height: f32,
253 pub name: ContainedText,
254 pub guest_avatar: ImageStyle,
255 pub guest_avatar_spacing: f32,
256}
257
258#[derive(Deserialize, Default)]
259pub struct ChatMessage {
260 #[serde(flatten)]
261 pub container: ContainerStyle,
262 pub body: TextStyle,
263 pub sender: ContainedText,
264 pub timestamp: ContainedText,
265}
266
267#[derive(Deserialize, Default)]
268pub struct ChannelSelect {
269 #[serde(flatten)]
270 pub container: ContainerStyle,
271 pub header: ChannelName,
272 pub item: ChannelName,
273 pub active_item: ChannelName,
274 pub hovered_item: ChannelName,
275 pub hovered_active_item: ChannelName,
276 pub menu: ContainerStyle,
277}
278
279#[derive(Deserialize, Default)]
280pub struct ChannelName {
281 #[serde(flatten)]
282 pub container: ContainerStyle,
283 pub hash: ContainedText,
284 pub name: TextStyle,
285}
286
287#[derive(Deserialize, Default)]
288pub struct Selector {
289 #[serde(flatten)]
290 pub container: ContainerStyle,
291 pub empty: ContainedLabel,
292 pub input_editor: FieldEditor,
293 pub item: ContainedLabel,
294 pub active_item: ContainedLabel,
295}
296
297#[derive(Clone, Debug, Deserialize, Default)]
298pub struct ContainedText {
299 #[serde(flatten)]
300 pub container: ContainerStyle,
301 #[serde(flatten)]
302 pub text: TextStyle,
303}
304
305#[derive(Clone, Debug, Deserialize, Default)]
306pub struct ContainedLabel {
307 #[serde(flatten)]
308 pub container: ContainerStyle,
309 #[serde(flatten)]
310 pub label: LabelStyle,
311}
312
313#[derive(Clone, Deserialize, Default)]
314pub struct ProjectDiagnostics {
315 #[serde(flatten)]
316 pub container: ContainerStyle,
317 pub empty_message: TextStyle,
318 pub status_bar_item: ContainedText,
319 pub tab_icon_width: f32,
320 pub tab_icon_spacing: f32,
321 pub tab_summary_spacing: f32,
322}
323
324#[derive(Clone, Deserialize, Default)]
325pub struct Editor {
326 pub text_color: Color,
327 #[serde(default)]
328 pub background: Color,
329 pub selection: SelectionStyle,
330 pub gutter_background: Color,
331 pub gutter_padding_factor: f32,
332 pub active_line_background: Color,
333 pub highlighted_line_background: Color,
334 pub rename_fade: f32,
335 pub document_highlight_read_background: Color,
336 pub document_highlight_write_background: Color,
337 pub diff_background_deleted: Color,
338 pub diff_background_inserted: Color,
339 pub line_number: Color,
340 pub line_number_active: Color,
341 pub guest_selections: Vec<SelectionStyle>,
342 pub syntax: Arc<SyntaxTheme>,
343 pub diagnostic_path_header: DiagnosticPathHeader,
344 pub diagnostic_header: DiagnosticHeader,
345 pub error_diagnostic: DiagnosticStyle,
346 pub invalid_error_diagnostic: DiagnosticStyle,
347 pub warning_diagnostic: DiagnosticStyle,
348 pub invalid_warning_diagnostic: DiagnosticStyle,
349 pub information_diagnostic: DiagnosticStyle,
350 pub invalid_information_diagnostic: DiagnosticStyle,
351 pub hint_diagnostic: DiagnosticStyle,
352 pub invalid_hint_diagnostic: DiagnosticStyle,
353 pub autocomplete: AutocompleteStyle,
354 pub code_actions_indicator: Color,
355 pub unnecessary_code_fade: f32,
356}
357
358#[derive(Clone, Deserialize, Default)]
359pub struct DiagnosticPathHeader {
360 #[serde(flatten)]
361 pub container: ContainerStyle,
362 pub filename: ContainedText,
363 pub path: ContainedText,
364 pub text_scale_factor: f32,
365}
366
367#[derive(Clone, Deserialize, Default)]
368pub struct DiagnosticHeader {
369 #[serde(flatten)]
370 pub container: ContainerStyle,
371 pub message: ContainedLabel,
372 pub code: ContainedText,
373 pub text_scale_factor: f32,
374 pub icon_width_factor: f32,
375}
376
377#[derive(Clone, Deserialize, Default)]
378pub struct DiagnosticStyle {
379 pub message: LabelStyle,
380 #[serde(default)]
381 pub header: ContainerStyle,
382 pub text_scale_factor: f32,
383}
384
385#[derive(Clone, Deserialize, Default)]
386pub struct AutocompleteStyle {
387 #[serde(flatten)]
388 pub container: ContainerStyle,
389 pub item: ContainerStyle,
390 pub selected_item: ContainerStyle,
391 pub hovered_item: ContainerStyle,
392 pub match_highlight: HighlightStyle,
393}
394
395#[derive(Clone, Copy, Default, Deserialize)]
396pub struct SelectionStyle {
397 pub cursor: Color,
398 pub selection: Color,
399}
400
401#[derive(Clone, Deserialize, Default)]
402pub struct FieldEditor {
403 #[serde(flatten)]
404 pub container: ContainerStyle,
405 pub text: TextStyle,
406 #[serde(default)]
407 pub placeholder_text: Option<TextStyle>,
408 pub selection: SelectionStyle,
409}
410
411impl Editor {
412 pub fn replica_selection_style(&self, replica_id: u16) -> &SelectionStyle {
413 let style_ix = replica_id as usize % (self.guest_selections.len() + 1);
414 if style_ix == 0 {
415 &self.selection
416 } else {
417 &self.guest_selections[style_ix - 1]
418 }
419 }
420}
421
422#[derive(Default)]
423pub struct SyntaxTheme {
424 pub highlights: Vec<(String, HighlightStyle)>,
425}
426
427impl SyntaxTheme {
428 pub fn new(highlights: Vec<(String, HighlightStyle)>) -> Self {
429 Self { highlights }
430 }
431}
432
433impl<'de> Deserialize<'de> for SyntaxTheme {
434 fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
435 where
436 D: serde::Deserializer<'de>,
437 {
438 let syntax_data: HashMap<String, HighlightStyle> = Deserialize::deserialize(deserializer)?;
439
440 let mut result = Self::new(Vec::new());
441 for (key, style) in syntax_data {
442 match result
443 .highlights
444 .binary_search_by(|(needle, _)| needle.cmp(&key))
445 {
446 Ok(i) | Err(i) => {
447 result.highlights.insert(i, (key, style));
448 }
449 }
450 }
451
452 Ok(result)
453 }
454}