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