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: Breadcrumbs,
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 max_editor_width: f32,
109 pub editor: FieldEditor,
110 pub invalid_editor: ContainerStyle,
111 pub option_button_group: ContainerStyle,
112 pub option_button: ContainedText,
113 pub active_option_button: ContainedText,
114 pub hovered_option_button: ContainedText,
115 pub active_hovered_option_button: ContainedText,
116 pub match_background: Color,
117 pub match_index: ContainedText,
118 pub results_status: TextStyle,
119 pub tab_icon_width: f32,
120 pub tab_icon_spacing: 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 Breadcrumbs {
277 pub text: TextStyle,
278}
279
280#[derive(Clone, Deserialize, Default)]
281pub struct Editor {
282 pub text_color: Color,
283 #[serde(default)]
284 pub background: Color,
285 pub selection: SelectionStyle,
286 pub gutter_background: Color,
287 pub gutter_padding_factor: f32,
288 pub active_line_background: Color,
289 pub highlighted_line_background: Color,
290 pub rename_fade: f32,
291 pub document_highlight_read_background: Color,
292 pub document_highlight_write_background: Color,
293 pub diff_background_deleted: Color,
294 pub diff_background_inserted: Color,
295 pub line_number: Color,
296 pub line_number_active: Color,
297 pub guest_selections: Vec<SelectionStyle>,
298 pub syntax: Arc<SyntaxTheme>,
299 pub diagnostic_path_header: DiagnosticPathHeader,
300 pub diagnostic_header: DiagnosticHeader,
301 pub error_diagnostic: DiagnosticStyle,
302 pub invalid_error_diagnostic: DiagnosticStyle,
303 pub warning_diagnostic: DiagnosticStyle,
304 pub invalid_warning_diagnostic: DiagnosticStyle,
305 pub information_diagnostic: DiagnosticStyle,
306 pub invalid_information_diagnostic: DiagnosticStyle,
307 pub hint_diagnostic: DiagnosticStyle,
308 pub invalid_hint_diagnostic: DiagnosticStyle,
309 pub autocomplete: AutocompleteStyle,
310 pub code_actions_indicator: Color,
311 pub unnecessary_code_fade: f32,
312}
313
314#[derive(Clone, Deserialize, Default)]
315pub struct DiagnosticPathHeader {
316 #[serde(flatten)]
317 pub container: ContainerStyle,
318 pub filename: ContainedText,
319 pub path: ContainedText,
320 pub text_scale_factor: f32,
321}
322
323#[derive(Clone, Deserialize, Default)]
324pub struct DiagnosticHeader {
325 #[serde(flatten)]
326 pub container: ContainerStyle,
327 pub message: ContainedLabel,
328 pub code: ContainedText,
329 pub text_scale_factor: f32,
330 pub icon_width_factor: f32,
331}
332
333#[derive(Clone, Deserialize, Default)]
334pub struct DiagnosticStyle {
335 pub message: LabelStyle,
336 #[serde(default)]
337 pub header: ContainerStyle,
338 pub text_scale_factor: f32,
339}
340
341#[derive(Clone, Deserialize, Default)]
342pub struct AutocompleteStyle {
343 #[serde(flatten)]
344 pub container: ContainerStyle,
345 pub item: ContainerStyle,
346 pub selected_item: ContainerStyle,
347 pub hovered_item: ContainerStyle,
348 pub match_highlight: HighlightStyle,
349}
350
351#[derive(Clone, Copy, Default, Deserialize)]
352pub struct SelectionStyle {
353 pub cursor: Color,
354 pub selection: Color,
355}
356
357#[derive(Clone, Deserialize, Default)]
358pub struct FieldEditor {
359 #[serde(flatten)]
360 pub container: ContainerStyle,
361 pub text: TextStyle,
362 #[serde(default)]
363 pub placeholder_text: Option<TextStyle>,
364 pub selection: SelectionStyle,
365}
366
367impl Editor {
368 pub fn replica_selection_style(&self, replica_id: u16) -> &SelectionStyle {
369 let style_ix = replica_id as usize % (self.guest_selections.len() + 1);
370 if style_ix == 0 {
371 &self.selection
372 } else {
373 &self.guest_selections[style_ix - 1]
374 }
375 }
376}
377
378#[derive(Default)]
379pub struct SyntaxTheme {
380 pub highlights: Vec<(String, HighlightStyle)>,
381}
382
383impl SyntaxTheme {
384 pub fn new(highlights: Vec<(String, HighlightStyle)>) -> Self {
385 Self { highlights }
386 }
387}
388
389impl<'de> Deserialize<'de> for SyntaxTheme {
390 fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
391 where
392 D: serde::Deserializer<'de>,
393 {
394 let syntax_data: HashMap<String, HighlightStyle> = Deserialize::deserialize(deserializer)?;
395
396 let mut result = Self::new(Vec::new());
397 for (key, style) in syntax_data {
398 match result
399 .highlights
400 .binary_search_by(|(needle, _)| needle.cmp(&key))
401 {
402 Ok(i) | Err(i) => {
403 result.highlights.insert(i, (key, style));
404 }
405 }
406 }
407
408 Ok(result)
409 }
410}