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