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