theme.rs

  1mod theme_registry;
  2
  3use gpui::{
  4    color::Color,
  5    elements::{ContainerStyle, ImageStyle, LabelStyle, Shadow, TooltipStyle},
  6    fonts::{HighlightStyle, TextStyle},
  7    Border, MouseState,
  8};
  9use serde::{de::DeserializeOwned, Deserialize};
 10use serde_json::Value;
 11use std::{collections::HashMap, sync::Arc};
 12
 13pub use theme_registry::*;
 14
 15#[derive(Deserialize, Default)]
 16pub struct Theme {
 17    #[serde(default)]
 18    pub meta: ThemeMeta,
 19    pub workspace: Workspace,
 20    pub context_menu: ContextMenu,
 21    pub contacts_popover: ContactsPopover,
 22    pub contact_list: ContactList,
 23    pub contact_finder: ContactFinder,
 24    pub project_panel: ProjectPanel,
 25    pub command_palette: CommandPalette,
 26    pub picker: Picker,
 27    pub editor: Editor,
 28    pub search: Search,
 29    pub project_diagnostics: ProjectDiagnostics,
 30    pub breadcrumbs: ContainedText,
 31    pub shared_screen: ContainerStyle,
 32    pub contact_notification: ContactNotification,
 33    pub update_notification: UpdateNotification,
 34    pub simple_message_notification: MessageNotification,
 35    pub project_shared_notification: ProjectSharedNotification,
 36    pub incoming_call_notification: IncomingCallNotification,
 37    pub tooltip: TooltipStyle,
 38    pub terminal: TerminalStyle,
 39    pub feedback: FeedbackStyle,
 40    pub color_scheme: ColorScheme,
 41}
 42
 43#[derive(Deserialize, Default, Clone)]
 44pub struct ThemeMeta {
 45    pub name: String,
 46    pub is_light: bool,
 47}
 48
 49#[derive(Deserialize, Default)]
 50pub struct Workspace {
 51    pub background: Color,
 52    pub titlebar: Titlebar,
 53    pub tab_bar: TabBar,
 54    pub pane_divider: Border,
 55    pub leader_border_opacity: f32,
 56    pub leader_border_width: f32,
 57    pub sidebar: Sidebar,
 58    pub status_bar: StatusBar,
 59    pub toolbar: Toolbar,
 60    pub disconnected_overlay: ContainedText,
 61    pub modal: ContainerStyle,
 62    pub notification: ContainerStyle,
 63    pub notifications: Notifications,
 64    pub joining_project_avatar: ImageStyle,
 65    pub joining_project_message: ContainedText,
 66    pub external_location_message: ContainedText,
 67    pub dock: Dock,
 68    pub drop_target_overlay_color: Color,
 69}
 70
 71#[derive(Clone, Deserialize, Default)]
 72pub struct Titlebar {
 73    #[serde(flatten)]
 74    pub container: ContainerStyle,
 75    pub height: f32,
 76    pub title: TextStyle,
 77    pub item_spacing: f32,
 78    pub face_pile_spacing: f32,
 79    pub avatar_ribbon: AvatarRibbon,
 80    pub follower_avatar_overlap: f32,
 81    pub leader_selection: ContainerStyle,
 82    pub offline_icon: OfflineIcon,
 83    pub leader_avatar: AvatarStyle,
 84    pub follower_avatar: AvatarStyle,
 85    pub inactive_avatar_grayscale: bool,
 86    pub sign_in_prompt: Interactive<ContainedText>,
 87    pub outdated_warning: ContainedText,
 88    pub share_button: Interactive<ContainedText>,
 89    pub call_control: Interactive<IconButton>,
 90    pub toggle_contacts_button: Interactive<IconButton>,
 91    pub user_menu_button: Interactive<IconButton>,
 92    pub toggle_contacts_badge: ContainerStyle,
 93}
 94
 95#[derive(Copy, Clone, Deserialize, Default)]
 96pub struct AvatarStyle {
 97    #[serde(flatten)]
 98    pub image: ImageStyle,
 99    pub outer_width: f32,
100    pub outer_corner_radius: f32,
101}
102
103#[derive(Deserialize, Default)]
104pub struct ContactsPopover {
105    #[serde(flatten)]
106    pub container: ContainerStyle,
107    pub height: f32,
108    pub width: f32,
109    pub invite_row_height: f32,
110    pub invite_row: Interactive<ContainedLabel>,
111}
112
113#[derive(Deserialize, Default)]
114pub struct ContactList {
115    pub user_query_editor: FieldEditor,
116    pub user_query_editor_height: f32,
117    pub add_contact_button: IconButton,
118    pub header_row: Interactive<ContainedText>,
119    pub leave_call: Interactive<ContainedText>,
120    pub contact_row: Interactive<ContainerStyle>,
121    pub row_height: f32,
122    pub project_row: Interactive<ProjectRow>,
123    pub tree_branch: Interactive<TreeBranch>,
124    pub contact_avatar: ImageStyle,
125    pub contact_status_free: ContainerStyle,
126    pub contact_status_busy: ContainerStyle,
127    pub contact_username: ContainedText,
128    pub contact_button: Interactive<IconButton>,
129    pub contact_button_spacing: f32,
130    pub disabled_button: IconButton,
131    pub section_icon_size: f32,
132    pub calling_indicator: ContainedText,
133}
134
135#[derive(Deserialize, Default)]
136pub struct ProjectRow {
137    #[serde(flatten)]
138    pub container: ContainerStyle,
139    pub icon: Icon,
140    pub name: ContainedText,
141}
142
143#[derive(Deserialize, Default, Clone, Copy)]
144pub struct TreeBranch {
145    pub width: f32,
146    pub color: Color,
147}
148
149#[derive(Deserialize, Default)]
150pub struct ContactFinder {
151    pub picker: Picker,
152    pub row_height: f32,
153    pub contact_avatar: ImageStyle,
154    pub contact_username: ContainerStyle,
155    pub contact_button: IconButton,
156    pub disabled_contact_button: IconButton,
157}
158
159#[derive(Clone, Deserialize, Default)]
160pub struct TabBar {
161    #[serde(flatten)]
162    pub container: ContainerStyle,
163    pub pane_button: Interactive<IconButton>,
164    pub pane_button_container: ContainerStyle,
165    pub active_pane: TabStyles,
166    pub inactive_pane: TabStyles,
167    pub dragged_tab: Tab,
168    pub height: f32,
169}
170
171impl TabBar {
172    pub fn tab_style(&self, pane_active: bool, tab_active: bool) -> &Tab {
173        let tabs = if pane_active {
174            &self.active_pane
175        } else {
176            &self.inactive_pane
177        };
178
179        if tab_active {
180            &tabs.active_tab
181        } else {
182            &tabs.inactive_tab
183        }
184    }
185}
186
187#[derive(Clone, Deserialize, Default)]
188pub struct TabStyles {
189    pub active_tab: Tab,
190    pub inactive_tab: Tab,
191}
192
193#[derive(Clone, Deserialize, Default)]
194pub struct AvatarRibbon {
195    #[serde(flatten)]
196    pub container: ContainerStyle,
197    pub width: f32,
198    pub height: f32,
199}
200
201#[derive(Clone, Deserialize, Default)]
202pub struct OfflineIcon {
203    #[serde(flatten)]
204    pub container: ContainerStyle,
205    pub width: f32,
206    pub color: Color,
207}
208
209#[derive(Clone, Deserialize, Default)]
210pub struct Tab {
211    pub height: f32,
212    #[serde(flatten)]
213    pub container: ContainerStyle,
214    #[serde(flatten)]
215    pub label: LabelStyle,
216    pub description: ContainedText,
217    pub spacing: f32,
218    pub icon_width: f32,
219    pub icon_close: Color,
220    pub icon_close_active: Color,
221    pub icon_dirty: Color,
222    pub icon_conflict: Color,
223}
224
225#[derive(Clone, Deserialize, Default)]
226pub struct Toolbar {
227    #[serde(flatten)]
228    pub container: ContainerStyle,
229    pub height: f32,
230    pub item_spacing: f32,
231    pub nav_button: Interactive<IconButton>,
232}
233
234#[derive(Clone, Deserialize, Default)]
235pub struct Dock {
236    pub initial_size_right: f32,
237    pub initial_size_bottom: f32,
238    pub wash_color: Color,
239    pub panel: ContainerStyle,
240    pub maximized: ContainerStyle,
241}
242
243#[derive(Clone, Deserialize, Default)]
244pub struct Notifications {
245    #[serde(flatten)]
246    pub container: ContainerStyle,
247    pub width: f32,
248}
249
250#[derive(Clone, Deserialize, Default)]
251pub struct Search {
252    #[serde(flatten)]
253    pub container: ContainerStyle,
254    pub editor: FindEditor,
255    pub invalid_editor: ContainerStyle,
256    pub option_button_group: ContainerStyle,
257    pub option_button: Interactive<ContainedText>,
258    pub match_background: Color,
259    pub match_index: ContainedText,
260    pub results_status: TextStyle,
261    pub dismiss_button: Interactive<IconButton>,
262}
263
264#[derive(Clone, Deserialize, Default)]
265pub struct FindEditor {
266    #[serde(flatten)]
267    pub input: FieldEditor,
268    pub min_width: f32,
269    pub max_width: f32,
270}
271
272#[derive(Deserialize, Default)]
273pub struct StatusBar {
274    #[serde(flatten)]
275    pub container: ContainerStyle,
276    pub height: f32,
277    pub item_spacing: f32,
278    pub cursor_position: TextStyle,
279    pub auto_update_progress_message: TextStyle,
280    pub auto_update_done_message: TextStyle,
281    pub lsp_status: Interactive<StatusBarLspStatus>,
282    pub feedback: Interactive<TextStyle>,
283    pub sidebar_buttons: StatusBarSidebarButtons,
284    pub diagnostic_summary: Interactive<StatusBarDiagnosticSummary>,
285    pub diagnostic_message: Interactive<ContainedText>,
286}
287
288#[derive(Deserialize, Default)]
289pub struct StatusBarSidebarButtons {
290    pub group_left: ContainerStyle,
291    pub group_right: ContainerStyle,
292    pub item: Interactive<SidebarItem>,
293    pub badge: ContainerStyle,
294}
295
296#[derive(Deserialize, Default)]
297pub struct StatusBarDiagnosticSummary {
298    pub container_ok: ContainerStyle,
299    pub container_warning: ContainerStyle,
300    pub container_error: ContainerStyle,
301    pub text: TextStyle,
302    pub icon_color_ok: Color,
303    pub icon_color_warning: Color,
304    pub icon_color_error: Color,
305    pub height: f32,
306    pub icon_width: f32,
307    pub icon_spacing: f32,
308    pub summary_spacing: f32,
309}
310
311#[derive(Deserialize, Default)]
312pub struct StatusBarLspStatus {
313    #[serde(flatten)]
314    pub container: ContainerStyle,
315    pub height: f32,
316    pub icon_spacing: f32,
317    pub icon_color: Color,
318    pub icon_width: f32,
319    pub message: TextStyle,
320}
321
322#[derive(Deserialize, Default)]
323pub struct Sidebar {
324    pub initial_size: f32,
325    #[serde(flatten)]
326    pub container: ContainerStyle,
327}
328
329#[derive(Clone, Copy, Deserialize, Default)]
330pub struct SidebarItem {
331    #[serde(flatten)]
332    pub container: ContainerStyle,
333    pub icon_color: Color,
334    pub icon_size: f32,
335}
336
337#[derive(Deserialize, Default)]
338pub struct ProjectPanel {
339    #[serde(flatten)]
340    pub container: ContainerStyle,
341    pub entry: Interactive<ProjectPanelEntry>,
342    pub dragged_entry: ProjectPanelEntry,
343    pub ignored_entry: Interactive<ProjectPanelEntry>,
344    pub cut_entry: Interactive<ProjectPanelEntry>,
345    pub filename_editor: FieldEditor,
346    pub indent_width: f32,
347}
348
349#[derive(Clone, Debug, Deserialize, Default)]
350pub struct ProjectPanelEntry {
351    pub height: f32,
352    #[serde(flatten)]
353    pub container: ContainerStyle,
354    pub text: TextStyle,
355    pub icon_color: Color,
356    pub icon_size: f32,
357    pub icon_spacing: f32,
358}
359
360#[derive(Clone, Debug, Deserialize, Default)]
361pub struct ContextMenu {
362    #[serde(flatten)]
363    pub container: ContainerStyle,
364    pub item: Interactive<ContextMenuItem>,
365    pub keystroke_margin: f32,
366    pub separator: ContainerStyle,
367}
368
369#[derive(Clone, Debug, Deserialize, Default)]
370pub struct ContextMenuItem {
371    #[serde(flatten)]
372    pub container: ContainerStyle,
373    pub label: TextStyle,
374    pub keystroke: ContainedText,
375    pub icon_width: f32,
376    pub icon_spacing: f32,
377}
378
379#[derive(Debug, Deserialize, Default)]
380pub struct CommandPalette {
381    pub key: Interactive<ContainedLabel>,
382    pub keystroke_spacing: f32,
383}
384
385#[derive(Deserialize, Default)]
386pub struct InviteLink {
387    #[serde(flatten)]
388    pub container: ContainerStyle,
389    #[serde(flatten)]
390    pub label: LabelStyle,
391    pub icon: Icon,
392}
393
394#[derive(Deserialize, Clone, Copy, Default)]
395pub struct Icon {
396    #[serde(flatten)]
397    pub container: ContainerStyle,
398    pub color: Color,
399    pub width: f32,
400}
401
402#[derive(Deserialize, Clone, Copy, Default)]
403pub struct IconButton {
404    #[serde(flatten)]
405    pub container: ContainerStyle,
406    pub color: Color,
407    pub icon_width: f32,
408    pub button_width: f32,
409}
410
411#[derive(Deserialize, Default)]
412pub struct ChatMessage {
413    #[serde(flatten)]
414    pub container: ContainerStyle,
415    pub body: TextStyle,
416    pub sender: ContainedText,
417    pub timestamp: ContainedText,
418}
419
420#[derive(Deserialize, Default)]
421pub struct ChannelSelect {
422    #[serde(flatten)]
423    pub container: ContainerStyle,
424    pub header: ChannelName,
425    pub item: ChannelName,
426    pub active_item: ChannelName,
427    pub hovered_item: ChannelName,
428    pub hovered_active_item: ChannelName,
429    pub menu: ContainerStyle,
430}
431
432#[derive(Deserialize, Default)]
433pub struct ChannelName {
434    #[serde(flatten)]
435    pub container: ContainerStyle,
436    pub hash: ContainedText,
437    pub name: TextStyle,
438}
439
440#[derive(Clone, Deserialize, Default)]
441pub struct Picker {
442    #[serde(flatten)]
443    pub container: ContainerStyle,
444    pub empty_container: ContainerStyle,
445    pub input_editor: FieldEditor,
446    pub empty_input_editor: FieldEditor,
447    pub no_matches: ContainedLabel,
448    pub item: Interactive<ContainedLabel>,
449}
450
451#[derive(Clone, Debug, Deserialize, Default)]
452pub struct ContainedText {
453    #[serde(flatten)]
454    pub container: ContainerStyle,
455    #[serde(flatten)]
456    pub text: TextStyle,
457}
458
459#[derive(Clone, Debug, Deserialize, Default)]
460pub struct ContainedLabel {
461    #[serde(flatten)]
462    pub container: ContainerStyle,
463    #[serde(flatten)]
464    pub label: LabelStyle,
465}
466
467#[derive(Clone, Deserialize, Default)]
468pub struct ProjectDiagnostics {
469    #[serde(flatten)]
470    pub container: ContainerStyle,
471    pub empty_message: TextStyle,
472    pub tab_icon_width: f32,
473    pub tab_icon_spacing: f32,
474    pub tab_summary_spacing: f32,
475}
476
477#[derive(Deserialize, Default)]
478pub struct ContactNotification {
479    pub header_avatar: ImageStyle,
480    pub header_message: ContainedText,
481    pub header_height: f32,
482    pub body_message: ContainedText,
483    pub button: Interactive<ContainedText>,
484    pub dismiss_button: Interactive<IconButton>,
485}
486
487#[derive(Deserialize, Default)]
488pub struct UpdateNotification {
489    pub message: ContainedText,
490    pub action_message: Interactive<ContainedText>,
491    pub dismiss_button: Interactive<IconButton>,
492}
493
494#[derive(Deserialize, Default)]
495pub struct MessageNotification {
496    pub message: ContainedText,
497    pub action_message: Interactive<ContainedText>,
498    pub dismiss_button: Interactive<IconButton>,
499}
500
501#[derive(Deserialize, Default)]
502pub struct ProjectSharedNotification {
503    pub window_height: f32,
504    pub window_width: f32,
505    #[serde(default)]
506    pub background: Color,
507    pub owner_container: ContainerStyle,
508    pub owner_avatar: ImageStyle,
509    pub owner_metadata: ContainerStyle,
510    pub owner_username: ContainedText,
511    pub message: ContainedText,
512    pub worktree_roots: ContainedText,
513    pub button_width: f32,
514    pub open_button: ContainedText,
515    pub dismiss_button: ContainedText,
516}
517
518#[derive(Deserialize, Default)]
519pub struct IncomingCallNotification {
520    pub window_height: f32,
521    pub window_width: f32,
522    #[serde(default)]
523    pub background: Color,
524    pub caller_container: ContainerStyle,
525    pub caller_avatar: ImageStyle,
526    pub caller_metadata: ContainerStyle,
527    pub caller_username: ContainedText,
528    pub caller_message: ContainedText,
529    pub worktree_roots: ContainedText,
530    pub button_width: f32,
531    pub accept_button: ContainedText,
532    pub decline_button: ContainedText,
533}
534
535#[derive(Clone, Deserialize, Default)]
536pub struct Editor {
537    pub text_color: Color,
538    #[serde(default)]
539    pub background: Color,
540    pub selection: SelectionStyle,
541    pub gutter_background: Color,
542    pub gutter_padding_factor: f32,
543    pub active_line_background: Color,
544    pub highlighted_line_background: Color,
545    pub rename_fade: f32,
546    pub document_highlight_read_background: Color,
547    pub document_highlight_write_background: Color,
548    pub diff: DiffStyle,
549    pub line_number: Color,
550    pub line_number_active: Color,
551    pub guest_selections: Vec<SelectionStyle>,
552    pub syntax: Arc<SyntaxTheme>,
553    pub diagnostic_path_header: DiagnosticPathHeader,
554    pub diagnostic_header: DiagnosticHeader,
555    pub error_diagnostic: DiagnosticStyle,
556    pub invalid_error_diagnostic: DiagnosticStyle,
557    pub warning_diagnostic: DiagnosticStyle,
558    pub invalid_warning_diagnostic: DiagnosticStyle,
559    pub information_diagnostic: DiagnosticStyle,
560    pub invalid_information_diagnostic: DiagnosticStyle,
561    pub hint_diagnostic: DiagnosticStyle,
562    pub invalid_hint_diagnostic: DiagnosticStyle,
563    pub autocomplete: AutocompleteStyle,
564    pub code_actions: CodeActions,
565    pub folds: Folds,
566    pub unnecessary_code_fade: f32,
567    pub hover_popover: HoverPopover,
568    pub link_definition: HighlightStyle,
569    pub composition_mark: HighlightStyle,
570    pub jump_icon: Interactive<IconButton>,
571    pub scrollbar: Scrollbar,
572}
573
574#[derive(Clone, Deserialize, Default)]
575pub struct Scrollbar {
576    pub track: ContainerStyle,
577    pub thumb: ContainerStyle,
578    pub width: f32,
579    pub min_height_factor: f32,
580}
581
582#[derive(Clone, Deserialize, Default)]
583pub struct DiagnosticPathHeader {
584    #[serde(flatten)]
585    pub container: ContainerStyle,
586    pub filename: ContainedText,
587    pub path: ContainedText,
588    pub text_scale_factor: f32,
589}
590
591#[derive(Clone, Deserialize, Default)]
592pub struct DiagnosticHeader {
593    #[serde(flatten)]
594    pub container: ContainerStyle,
595    pub message: ContainedLabel,
596    pub code: ContainedText,
597    pub text_scale_factor: f32,
598    pub icon_width_factor: f32,
599}
600
601#[derive(Clone, Deserialize, Default)]
602pub struct DiagnosticStyle {
603    pub message: LabelStyle,
604    #[serde(default)]
605    pub header: ContainerStyle,
606    pub text_scale_factor: f32,
607}
608
609#[derive(Clone, Deserialize, Default)]
610pub struct AutocompleteStyle {
611    #[serde(flatten)]
612    pub container: ContainerStyle,
613    pub item: ContainerStyle,
614    pub selected_item: ContainerStyle,
615    pub hovered_item: ContainerStyle,
616    pub match_highlight: HighlightStyle,
617}
618
619#[derive(Clone, Copy, Default, Deserialize)]
620pub struct SelectionStyle {
621    pub cursor: Color,
622    pub selection: Color,
623}
624
625#[derive(Clone, Deserialize, Default)]
626pub struct FieldEditor {
627    #[serde(flatten)]
628    pub container: ContainerStyle,
629    pub text: TextStyle,
630    #[serde(default)]
631    pub placeholder_text: Option<TextStyle>,
632    pub selection: SelectionStyle,
633}
634
635#[derive(Clone, Deserialize, Default)]
636pub struct CodeActions {
637    #[serde(default)]
638    pub indicator: Interactive<Indicator>,
639    pub vertical_scale: f32,
640}
641
642#[derive(Clone, Deserialize, Default)]
643pub struct Folds {
644    pub indicator: Interactive<Indicator>,
645    pub fold_background: Color,
646    pub icon_width: f32,
647    pub folded_icon: String,
648    pub foldable_icon: String,
649}
650
651#[derive(Clone, Deserialize, Default)]
652pub struct Indicator {
653    pub color: Color,
654}
655
656#[derive(Clone, Deserialize, Default)]
657pub struct DiffStyle {
658    pub inserted: Color,
659    pub modified: Color,
660    pub deleted: Color,
661    pub removed_width_em: f32,
662    pub width_em: f32,
663    pub corner_radius: f32,
664}
665
666#[derive(Debug, Default, Clone, Copy)]
667pub struct Interactive<T> {
668    pub default: T,
669    pub hover: Option<T>,
670    pub clicked: Option<T>,
671    pub active: Option<T>,
672    pub disabled: Option<T>,
673}
674
675impl<T> Interactive<T> {
676    pub fn style_for(&self, state: &mut MouseState, active: bool) -> &T {
677        if active {
678            self.active.as_ref().unwrap_or(&self.default)
679        } else if state.clicked() == Some(gpui::MouseButton::Left) && self.clicked.is_some() {
680            self.clicked.as_ref().unwrap()
681        } else if state.hovered() {
682            self.hover.as_ref().unwrap_or(&self.default)
683        } else {
684            &self.default
685        }
686    }
687
688    pub fn disabled_style(&self) -> &T {
689        self.disabled.as_ref().unwrap_or(&self.default)
690    }
691}
692
693impl<'de, T: DeserializeOwned> Deserialize<'de> for Interactive<T> {
694    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
695    where
696        D: serde::Deserializer<'de>,
697    {
698        #[derive(Deserialize)]
699        struct Helper {
700            #[serde(flatten)]
701            default: Value,
702            hover: Option<Value>,
703            clicked: Option<Value>,
704            active: Option<Value>,
705            disabled: Option<Value>,
706        }
707
708        let json = Helper::deserialize(deserializer)?;
709
710        let deserialize_state = |state_json: Option<Value>| -> Result<Option<T>, D::Error> {
711            if let Some(mut state_json) = state_json {
712                if let Value::Object(state_json) = &mut state_json {
713                    if let Value::Object(default) = &json.default {
714                        for (key, value) in default {
715                            if !state_json.contains_key(key) {
716                                state_json.insert(key.clone(), value.clone());
717                            }
718                        }
719                    }
720                }
721                Ok(Some(
722                    serde_json::from_value::<T>(state_json).map_err(serde::de::Error::custom)?,
723                ))
724            } else {
725                Ok(None)
726            }
727        };
728
729        let hover = deserialize_state(json.hover)?;
730        let clicked = deserialize_state(json.clicked)?;
731        let active = deserialize_state(json.active)?;
732        let disabled = deserialize_state(json.disabled)?;
733        let default = serde_json::from_value(json.default).map_err(serde::de::Error::custom)?;
734
735        Ok(Interactive {
736            default,
737            hover,
738            clicked,
739            active,
740            disabled,
741        })
742    }
743}
744
745impl Editor {
746    pub fn replica_selection_style(&self, replica_id: u16) -> &SelectionStyle {
747        let style_ix = replica_id as usize % (self.guest_selections.len() + 1);
748        if style_ix == 0 {
749            &self.selection
750        } else {
751            &self.guest_selections[style_ix - 1]
752        }
753    }
754}
755
756#[derive(Default)]
757pub struct SyntaxTheme {
758    pub highlights: Vec<(String, HighlightStyle)>,
759}
760
761impl SyntaxTheme {
762    pub fn new(highlights: Vec<(String, HighlightStyle)>) -> Self {
763        Self { highlights }
764    }
765}
766
767impl<'de> Deserialize<'de> for SyntaxTheme {
768    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
769    where
770        D: serde::Deserializer<'de>,
771    {
772        let syntax_data: HashMap<String, HighlightStyle> = Deserialize::deserialize(deserializer)?;
773
774        let mut result = Self::new(Vec::new());
775        for (key, style) in syntax_data {
776            match result
777                .highlights
778                .binary_search_by(|(needle, _)| needle.cmp(&key))
779            {
780                Ok(i) | Err(i) => {
781                    result.highlights.insert(i, (key, style));
782                }
783            }
784        }
785
786        Ok(result)
787    }
788}
789
790#[derive(Clone, Deserialize, Default)]
791pub struct HoverPopover {
792    pub container: ContainerStyle,
793    pub info_container: ContainerStyle,
794    pub warning_container: ContainerStyle,
795    pub error_container: ContainerStyle,
796    pub block_style: ContainerStyle,
797    pub prose: TextStyle,
798    pub highlight: Color,
799}
800
801#[derive(Clone, Deserialize, Default)]
802pub struct TerminalStyle {
803    pub black: Color,
804    pub red: Color,
805    pub green: Color,
806    pub yellow: Color,
807    pub blue: Color,
808    pub magenta: Color,
809    pub cyan: Color,
810    pub white: Color,
811    pub bright_black: Color,
812    pub bright_red: Color,
813    pub bright_green: Color,
814    pub bright_yellow: Color,
815    pub bright_blue: Color,
816    pub bright_magenta: Color,
817    pub bright_cyan: Color,
818    pub bright_white: Color,
819    pub foreground: Color,
820    pub background: Color,
821    pub modal_background: Color,
822    pub cursor: Color,
823    pub dim_black: Color,
824    pub dim_red: Color,
825    pub dim_green: Color,
826    pub dim_yellow: Color,
827    pub dim_blue: Color,
828    pub dim_magenta: Color,
829    pub dim_cyan: Color,
830    pub dim_white: Color,
831    pub bright_foreground: Color,
832    pub dim_foreground: Color,
833}
834
835#[derive(Clone, Deserialize, Default)]
836pub struct FeedbackStyle {
837    pub submit_button: Interactive<ContainedText>,
838    pub button_margin: f32,
839    pub info_text_default: ContainedText,
840    pub link_text_default: ContainedText,
841    pub link_text_hover: ContainedText,
842}
843
844#[derive(Clone, Deserialize, Default)]
845pub struct ColorScheme {
846    pub name: String,
847    pub is_light: bool,
848
849    pub ramps: RampSet,
850
851    pub lowest: Layer,
852    pub middle: Layer,
853    pub highest: Layer,
854
855    pub popover_shadow: Shadow,
856    pub modal_shadow: Shadow,
857
858    pub players: Vec<Player>,
859}
860
861#[derive(Clone, Deserialize, Default)]
862pub struct Player {
863    pub cursor: Color,
864    pub selection: Color,
865}
866
867#[derive(Clone, Deserialize, Default)]
868pub struct RampSet {
869    pub neutral: Vec<Color>,
870    pub red: Vec<Color>,
871    pub orange: Vec<Color>,
872    pub yellow: Vec<Color>,
873    pub green: Vec<Color>,
874    pub cyan: Vec<Color>,
875    pub blue: Vec<Color>,
876    pub violet: Vec<Color>,
877    pub magenta: Vec<Color>,
878}
879
880#[derive(Clone, Deserialize, Default)]
881pub struct Layer {
882    pub base: StyleSet,
883    pub variant: StyleSet,
884    pub on: StyleSet,
885    pub accent: StyleSet,
886    pub positive: StyleSet,
887    pub warning: StyleSet,
888    pub negative: StyleSet,
889}
890
891#[derive(Clone, Deserialize, Default)]
892pub struct StyleSet {
893    pub default: Style,
894    pub active: Style,
895    pub disabled: Style,
896    pub hovered: Style,
897    pub pressed: Style,
898    pub inverted: Style,
899}
900
901#[derive(Clone, Deserialize, Default)]
902pub struct Style {
903    pub background: Color,
904    pub border: Color,
905    pub foreground: Color,
906}