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 rename_fade: f32,
286 pub document_highlight_read_background: Color,
287 pub document_highlight_write_background: Color,
288 pub diff_background_deleted: Color,
289 pub diff_background_inserted: Color,
290 pub line_number: Color,
291 pub line_number_active: Color,
292 pub guest_selections: Vec<SelectionStyle>,
293 pub syntax: Arc<SyntaxTheme>,
294 pub diagnostic_path_header: DiagnosticPathHeader,
295 pub diagnostic_header: DiagnosticHeader,
296 pub error_diagnostic: DiagnosticStyle,
297 pub invalid_error_diagnostic: DiagnosticStyle,
298 pub warning_diagnostic: DiagnosticStyle,
299 pub invalid_warning_diagnostic: DiagnosticStyle,
300 pub information_diagnostic: DiagnosticStyle,
301 pub invalid_information_diagnostic: DiagnosticStyle,
302 pub hint_diagnostic: DiagnosticStyle,
303 pub invalid_hint_diagnostic: DiagnosticStyle,
304 pub autocomplete: AutocompleteStyle,
305 pub code_actions_indicator: Color,
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}