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