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