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 #[serde(flatten)]
98 pub container: ContainerStyle,
99 pub height: f32,
100 pub item_spacing: f32,
101}
102
103#[derive(Clone, Deserialize, Default)]
104pub struct Search {
105 #[serde(flatten)]
106 pub container: ContainerStyle,
107 pub max_editor_width: f32,
108 pub editor: FieldEditor,
109 pub invalid_editor: ContainerStyle,
110 pub option_button_group: ContainerStyle,
111 pub option_button: ContainedText,
112 pub active_option_button: ContainedText,
113 pub hovered_option_button: ContainedText,
114 pub active_hovered_option_button: ContainedText,
115 pub match_background: Color,
116 pub match_index: ContainedText,
117 pub results_status: TextStyle,
118 pub tab_icon_width: f32,
119 pub tab_icon_spacing: 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 rename_fade: f32,
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 pub unnecessary_code_fade: f32,
306}
307
308#[derive(Clone, Deserialize, Default)]
309pub struct DiagnosticPathHeader {
310 #[serde(flatten)]
311 pub container: ContainerStyle,
312 pub filename: ContainedText,
313 pub path: ContainedText,
314 pub text_scale_factor: f32,
315}
316
317#[derive(Clone, Deserialize, Default)]
318pub struct DiagnosticHeader {
319 #[serde(flatten)]
320 pub container: ContainerStyle,
321 pub message: ContainedLabel,
322 pub code: ContainedText,
323 pub text_scale_factor: f32,
324 pub icon_width_factor: f32,
325}
326
327#[derive(Clone, Deserialize, Default)]
328pub struct DiagnosticStyle {
329 pub message: LabelStyle,
330 #[serde(default)]
331 pub header: ContainerStyle,
332 pub text_scale_factor: f32,
333}
334
335#[derive(Clone, Deserialize, Default)]
336pub struct AutocompleteStyle {
337 #[serde(flatten)]
338 pub container: ContainerStyle,
339 pub item: ContainerStyle,
340 pub selected_item: ContainerStyle,
341 pub hovered_item: ContainerStyle,
342 pub match_highlight: HighlightStyle,
343}
344
345#[derive(Clone, Copy, Default, Deserialize)]
346pub struct SelectionStyle {
347 pub cursor: Color,
348 pub selection: Color,
349}
350
351#[derive(Clone, Deserialize, Default)]
352pub struct FieldEditor {
353 #[serde(flatten)]
354 pub container: ContainerStyle,
355 pub text: TextStyle,
356 #[serde(default)]
357 pub placeholder_text: Option<TextStyle>,
358 pub selection: SelectionStyle,
359}
360
361impl Editor {
362 pub fn replica_selection_style(&self, replica_id: u16) -> &SelectionStyle {
363 let style_ix = replica_id as usize % (self.guest_selections.len() + 1);
364 if style_ix == 0 {
365 &self.selection
366 } else {
367 &self.guest_selections[style_ix - 1]
368 }
369 }
370}
371
372#[derive(Default)]
373pub struct SyntaxTheme {
374 pub highlights: Vec<(String, HighlightStyle)>,
375}
376
377impl SyntaxTheme {
378 pub fn new(highlights: Vec<(String, HighlightStyle)>) -> Self {
379 Self { highlights }
380 }
381}
382
383impl<'de> Deserialize<'de> for SyntaxTheme {
384 fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
385 where
386 D: serde::Deserializer<'de>,
387 {
388 let syntax_data: HashMap<String, HighlightStyle> = Deserialize::deserialize(deserializer)?;
389
390 let mut result = Self::new(Vec::new());
391 for (key, style) in syntax_data {
392 match result
393 .highlights
394 .binary_search_by(|(needle, _)| needle.cmp(&key))
395 {
396 Ok(i) | Err(i) => {
397 result.highlights.insert(i, (key, style));
398 }
399 }
400 }
401
402 Ok(result)
403 }
404}