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 tab_icon_width: f32,
262    pub tab_icon_spacing: f32,
263    pub dismiss_button: Interactive<IconButton>,
264}
265
266#[derive(Clone, Deserialize, Default)]
267pub struct FindEditor {
268    #[serde(flatten)]
269    pub input: FieldEditor,
270    pub min_width: f32,
271    pub max_width: f32,
272}
273
274#[derive(Deserialize, Default)]
275pub struct StatusBar {
276    #[serde(flatten)]
277    pub container: ContainerStyle,
278    pub height: f32,
279    pub item_spacing: f32,
280    pub cursor_position: TextStyle,
281    pub auto_update_progress_message: TextStyle,
282    pub auto_update_done_message: TextStyle,
283    pub lsp_status: Interactive<StatusBarLspStatus>,
284    pub feedback: Interactive<TextStyle>,
285    pub sidebar_buttons: StatusBarSidebarButtons,
286    pub diagnostic_summary: Interactive<StatusBarDiagnosticSummary>,
287    pub diagnostic_message: Interactive<ContainedText>,
288}
289
290#[derive(Deserialize, Default)]
291pub struct StatusBarSidebarButtons {
292    pub group_left: ContainerStyle,
293    pub group_right: ContainerStyle,
294    pub item: Interactive<SidebarItem>,
295    pub badge: ContainerStyle,
296}
297
298#[derive(Deserialize, Default)]
299pub struct StatusBarDiagnosticSummary {
300    pub container_ok: ContainerStyle,
301    pub container_warning: ContainerStyle,
302    pub container_error: ContainerStyle,
303    pub text: TextStyle,
304    pub icon_color_ok: Color,
305    pub icon_color_warning: Color,
306    pub icon_color_error: Color,
307    pub height: f32,
308    pub icon_width: f32,
309    pub icon_spacing: f32,
310    pub summary_spacing: f32,
311}
312
313#[derive(Deserialize, Default)]
314pub struct StatusBarLspStatus {
315    #[serde(flatten)]
316    pub container: ContainerStyle,
317    pub height: f32,
318    pub icon_spacing: f32,
319    pub icon_color: Color,
320    pub icon_width: f32,
321    pub message: TextStyle,
322}
323
324#[derive(Deserialize, Default)]
325pub struct Sidebar {
326    pub initial_size: f32,
327    #[serde(flatten)]
328    pub container: ContainerStyle,
329}
330
331#[derive(Clone, Copy, Deserialize, Default)]
332pub struct SidebarItem {
333    #[serde(flatten)]
334    pub container: ContainerStyle,
335    pub icon_color: Color,
336    pub icon_size: f32,
337}
338
339#[derive(Deserialize, Default)]
340pub struct ProjectPanel {
341    #[serde(flatten)]
342    pub container: ContainerStyle,
343    pub entry: Interactive<ProjectPanelEntry>,
344    pub dragged_entry: ProjectPanelEntry,
345    pub ignored_entry: Interactive<ProjectPanelEntry>,
346    pub cut_entry: Interactive<ProjectPanelEntry>,
347    pub filename_editor: FieldEditor,
348    pub indent_width: f32,
349}
350
351#[derive(Clone, Debug, Deserialize, Default)]
352pub struct ProjectPanelEntry {
353    pub height: f32,
354    #[serde(flatten)]
355    pub container: ContainerStyle,
356    pub text: TextStyle,
357    pub icon_color: Color,
358    pub icon_size: f32,
359    pub icon_spacing: f32,
360}
361
362#[derive(Clone, Debug, Deserialize, Default)]
363pub struct ContextMenu {
364    #[serde(flatten)]
365    pub container: ContainerStyle,
366    pub item: Interactive<ContextMenuItem>,
367    pub keystroke_margin: f32,
368    pub separator: ContainerStyle,
369}
370
371#[derive(Clone, Debug, Deserialize, Default)]
372pub struct ContextMenuItem {
373    #[serde(flatten)]
374    pub container: ContainerStyle,
375    pub label: TextStyle,
376    pub keystroke: ContainedText,
377    pub icon_width: f32,
378    pub icon_spacing: f32,
379}
380
381#[derive(Debug, Deserialize, Default)]
382pub struct CommandPalette {
383    pub key: Interactive<ContainedLabel>,
384    pub keystroke_spacing: f32,
385}
386
387#[derive(Deserialize, Default)]
388pub struct InviteLink {
389    #[serde(flatten)]
390    pub container: ContainerStyle,
391    #[serde(flatten)]
392    pub label: LabelStyle,
393    pub icon: Icon,
394}
395
396#[derive(Deserialize, Clone, Copy, Default)]
397pub struct Icon {
398    #[serde(flatten)]
399    pub container: ContainerStyle,
400    pub color: Color,
401    pub width: f32,
402}
403
404#[derive(Deserialize, Clone, Copy, Default)]
405pub struct IconButton {
406    #[serde(flatten)]
407    pub container: ContainerStyle,
408    pub color: Color,
409    pub icon_width: f32,
410    pub button_width: f32,
411}
412
413#[derive(Deserialize, Default)]
414pub struct ChatMessage {
415    #[serde(flatten)]
416    pub container: ContainerStyle,
417    pub body: TextStyle,
418    pub sender: ContainedText,
419    pub timestamp: ContainedText,
420}
421
422#[derive(Deserialize, Default)]
423pub struct ChannelSelect {
424    #[serde(flatten)]
425    pub container: ContainerStyle,
426    pub header: ChannelName,
427    pub item: ChannelName,
428    pub active_item: ChannelName,
429    pub hovered_item: ChannelName,
430    pub hovered_active_item: ChannelName,
431    pub menu: ContainerStyle,
432}
433
434#[derive(Deserialize, Default)]
435pub struct ChannelName {
436    #[serde(flatten)]
437    pub container: ContainerStyle,
438    pub hash: ContainedText,
439    pub name: TextStyle,
440}
441
442#[derive(Clone, Deserialize, Default)]
443pub struct Picker {
444    #[serde(flatten)]
445    pub container: ContainerStyle,
446    pub empty_container: ContainerStyle,
447    pub input_editor: FieldEditor,
448    pub empty_input_editor: FieldEditor,
449    pub no_matches: ContainedLabel,
450    pub item: Interactive<ContainedLabel>,
451}
452
453#[derive(Clone, Debug, Deserialize, Default)]
454pub struct ContainedText {
455    #[serde(flatten)]
456    pub container: ContainerStyle,
457    #[serde(flatten)]
458    pub text: TextStyle,
459}
460
461#[derive(Clone, Debug, Deserialize, Default)]
462pub struct ContainedLabel {
463    #[serde(flatten)]
464    pub container: ContainerStyle,
465    #[serde(flatten)]
466    pub label: LabelStyle,
467}
468
469#[derive(Clone, Deserialize, Default)]
470pub struct ProjectDiagnostics {
471    #[serde(flatten)]
472    pub container: ContainerStyle,
473    pub empty_message: TextStyle,
474    pub tab_icon_width: f32,
475    pub tab_icon_spacing: f32,
476    pub tab_summary_spacing: f32,
477}
478
479#[derive(Deserialize, Default)]
480pub struct ContactNotification {
481    pub header_avatar: ImageStyle,
482    pub header_message: ContainedText,
483    pub header_height: f32,
484    pub body_message: ContainedText,
485    pub button: Interactive<ContainedText>,
486    pub dismiss_button: Interactive<IconButton>,
487}
488
489#[derive(Deserialize, Default)]
490pub struct UpdateNotification {
491    pub message: ContainedText,
492    pub action_message: Interactive<ContainedText>,
493    pub dismiss_button: Interactive<IconButton>,
494}
495
496#[derive(Deserialize, Default)]
497pub struct MessageNotification {
498    pub message: ContainedText,
499    pub action_message: Interactive<ContainedText>,
500    pub dismiss_button: Interactive<IconButton>,
501}
502
503#[derive(Deserialize, Default)]
504pub struct ProjectSharedNotification {
505    pub window_height: f32,
506    pub window_width: f32,
507    #[serde(default)]
508    pub background: Color,
509    pub owner_container: ContainerStyle,
510    pub owner_avatar: ImageStyle,
511    pub owner_metadata: ContainerStyle,
512    pub owner_username: ContainedText,
513    pub message: ContainedText,
514    pub worktree_roots: ContainedText,
515    pub button_width: f32,
516    pub open_button: ContainedText,
517    pub dismiss_button: ContainedText,
518}
519
520#[derive(Deserialize, Default)]
521pub struct IncomingCallNotification {
522    pub window_height: f32,
523    pub window_width: f32,
524    #[serde(default)]
525    pub background: Color,
526    pub caller_container: ContainerStyle,
527    pub caller_avatar: ImageStyle,
528    pub caller_metadata: ContainerStyle,
529    pub caller_username: ContainedText,
530    pub caller_message: ContainedText,
531    pub worktree_roots: ContainedText,
532    pub button_width: f32,
533    pub accept_button: ContainedText,
534    pub decline_button: ContainedText,
535}
536
537#[derive(Clone, Deserialize, Default)]
538pub struct Editor {
539    pub text_color: Color,
540    #[serde(default)]
541    pub background: Color,
542    pub selection: SelectionStyle,
543    pub gutter_background: Color,
544    pub gutter_padding_factor: f32,
545    pub active_line_background: Color,
546    pub highlighted_line_background: Color,
547    pub rename_fade: f32,
548    pub document_highlight_read_background: Color,
549    pub document_highlight_write_background: Color,
550    pub diff: DiffStyle,
551    pub line_number: Color,
552    pub line_number_active: Color,
553    pub guest_selections: Vec<SelectionStyle>,
554    pub syntax: Arc<SyntaxTheme>,
555    pub diagnostic_path_header: DiagnosticPathHeader,
556    pub diagnostic_header: DiagnosticHeader,
557    pub error_diagnostic: DiagnosticStyle,
558    pub invalid_error_diagnostic: DiagnosticStyle,
559    pub warning_diagnostic: DiagnosticStyle,
560    pub invalid_warning_diagnostic: DiagnosticStyle,
561    pub information_diagnostic: DiagnosticStyle,
562    pub invalid_information_diagnostic: DiagnosticStyle,
563    pub hint_diagnostic: DiagnosticStyle,
564    pub invalid_hint_diagnostic: DiagnosticStyle,
565    pub autocomplete: AutocompleteStyle,
566    pub code_actions: CodeActions,
567    pub unnecessary_code_fade: f32,
568    pub hover_popover: HoverPopover,
569    pub link_definition: HighlightStyle,
570    pub composition_mark: HighlightStyle,
571    pub jump_icon: Interactive<IconButton>,
572    pub scrollbar: Scrollbar,
573}
574
575#[derive(Clone, Deserialize, Default)]
576pub struct Scrollbar {
577    pub track: ContainerStyle,
578    pub thumb: ContainerStyle,
579    pub width: f32,
580    pub min_height_factor: f32,
581}
582
583#[derive(Clone, Deserialize, Default)]
584pub struct DiagnosticPathHeader {
585    #[serde(flatten)]
586    pub container: ContainerStyle,
587    pub filename: ContainedText,
588    pub path: ContainedText,
589    pub text_scale_factor: f32,
590}
591
592#[derive(Clone, Deserialize, Default)]
593pub struct DiagnosticHeader {
594    #[serde(flatten)]
595    pub container: ContainerStyle,
596    pub message: ContainedLabel,
597    pub code: ContainedText,
598    pub text_scale_factor: f32,
599    pub icon_width_factor: f32,
600}
601
602#[derive(Clone, Deserialize, Default)]
603pub struct DiagnosticStyle {
604    pub message: LabelStyle,
605    #[serde(default)]
606    pub header: ContainerStyle,
607    pub text_scale_factor: f32,
608}
609
610#[derive(Clone, Deserialize, Default)]
611pub struct AutocompleteStyle {
612    #[serde(flatten)]
613    pub container: ContainerStyle,
614    pub item: ContainerStyle,
615    pub selected_item: ContainerStyle,
616    pub hovered_item: ContainerStyle,
617    pub match_highlight: HighlightStyle,
618}
619
620#[derive(Clone, Copy, Default, Deserialize)]
621pub struct SelectionStyle {
622    pub cursor: Color,
623    pub selection: Color,
624}
625
626#[derive(Clone, Deserialize, Default)]
627pub struct FieldEditor {
628    #[serde(flatten)]
629    pub container: ContainerStyle,
630    pub text: TextStyle,
631    #[serde(default)]
632    pub placeholder_text: Option<TextStyle>,
633    pub selection: SelectionStyle,
634}
635
636#[derive(Clone, Deserialize, Default)]
637pub struct CodeActions {
638    #[serde(default)]
639    pub indicator: Color,
640    pub vertical_scale: f32,
641}
642
643#[derive(Clone, Deserialize, Default)]
644pub struct DiffStyle {
645    pub inserted: Color,
646    pub modified: Color,
647    pub deleted: Color,
648    pub removed_width_em: f32,
649    pub width_em: f32,
650    pub corner_radius: f32,
651}
652
653#[derive(Debug, Default, Clone, Copy)]
654pub struct Interactive<T> {
655    pub default: T,
656    pub hover: Option<T>,
657    pub clicked: Option<T>,
658    pub active: Option<T>,
659    pub disabled: Option<T>,
660}
661
662impl<T> Interactive<T> {
663    pub fn style_for(&self, state: &mut MouseState, active: bool) -> &T {
664        if active {
665            self.active.as_ref().unwrap_or(&self.default)
666        } else if state.clicked() == Some(gpui::MouseButton::Left) && self.clicked.is_some() {
667            self.clicked.as_ref().unwrap()
668        } else if state.hovered() {
669            self.hover.as_ref().unwrap_or(&self.default)
670        } else {
671            &self.default
672        }
673    }
674
675    pub fn disabled_style(&self) -> &T {
676        self.disabled.as_ref().unwrap_or(&self.default)
677    }
678}
679
680impl<'de, T: DeserializeOwned> Deserialize<'de> for Interactive<T> {
681    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
682    where
683        D: serde::Deserializer<'de>,
684    {
685        #[derive(Deserialize)]
686        struct Helper {
687            #[serde(flatten)]
688            default: Value,
689            hover: Option<Value>,
690            clicked: Option<Value>,
691            active: Option<Value>,
692            disabled: Option<Value>,
693        }
694
695        let json = Helper::deserialize(deserializer)?;
696
697        let deserialize_state = |state_json: Option<Value>| -> Result<Option<T>, D::Error> {
698            if let Some(mut state_json) = state_json {
699                if let Value::Object(state_json) = &mut state_json {
700                    if let Value::Object(default) = &json.default {
701                        for (key, value) in default {
702                            if !state_json.contains_key(key) {
703                                state_json.insert(key.clone(), value.clone());
704                            }
705                        }
706                    }
707                }
708                Ok(Some(
709                    serde_json::from_value::<T>(state_json).map_err(serde::de::Error::custom)?,
710                ))
711            } else {
712                Ok(None)
713            }
714        };
715
716        let hover = deserialize_state(json.hover)?;
717        let clicked = deserialize_state(json.clicked)?;
718        let active = deserialize_state(json.active)?;
719        let disabled = deserialize_state(json.disabled)?;
720        let default = serde_json::from_value(json.default).map_err(serde::de::Error::custom)?;
721
722        Ok(Interactive {
723            default,
724            hover,
725            clicked,
726            active,
727            disabled,
728        })
729    }
730}
731
732impl Editor {
733    pub fn replica_selection_style(&self, replica_id: u16) -> &SelectionStyle {
734        let style_ix = replica_id as usize % (self.guest_selections.len() + 1);
735        if style_ix == 0 {
736            &self.selection
737        } else {
738            &self.guest_selections[style_ix - 1]
739        }
740    }
741}
742
743#[derive(Default)]
744pub struct SyntaxTheme {
745    pub highlights: Vec<(String, HighlightStyle)>,
746}
747
748impl SyntaxTheme {
749    pub fn new(highlights: Vec<(String, HighlightStyle)>) -> Self {
750        Self { highlights }
751    }
752}
753
754impl<'de> Deserialize<'de> for SyntaxTheme {
755    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
756    where
757        D: serde::Deserializer<'de>,
758    {
759        let syntax_data: HashMap<String, HighlightStyle> = Deserialize::deserialize(deserializer)?;
760
761        let mut result = Self::new(Vec::new());
762        for (key, style) in syntax_data {
763            match result
764                .highlights
765                .binary_search_by(|(needle, _)| needle.cmp(&key))
766            {
767                Ok(i) | Err(i) => {
768                    result.highlights.insert(i, (key, style));
769                }
770            }
771        }
772
773        Ok(result)
774    }
775}
776
777#[derive(Clone, Deserialize, Default)]
778pub struct HoverPopover {
779    pub container: ContainerStyle,
780    pub info_container: ContainerStyle,
781    pub warning_container: ContainerStyle,
782    pub error_container: ContainerStyle,
783    pub block_style: ContainerStyle,
784    pub prose: TextStyle,
785    pub highlight: Color,
786}
787
788#[derive(Clone, Deserialize, Default)]
789pub struct TerminalStyle {
790    pub black: Color,
791    pub red: Color,
792    pub green: Color,
793    pub yellow: Color,
794    pub blue: Color,
795    pub magenta: Color,
796    pub cyan: Color,
797    pub white: Color,
798    pub bright_black: Color,
799    pub bright_red: Color,
800    pub bright_green: Color,
801    pub bright_yellow: Color,
802    pub bright_blue: Color,
803    pub bright_magenta: Color,
804    pub bright_cyan: Color,
805    pub bright_white: Color,
806    pub foreground: Color,
807    pub background: Color,
808    pub modal_background: Color,
809    pub cursor: Color,
810    pub dim_black: Color,
811    pub dim_red: Color,
812    pub dim_green: Color,
813    pub dim_yellow: Color,
814    pub dim_blue: Color,
815    pub dim_magenta: Color,
816    pub dim_cyan: Color,
817    pub dim_white: Color,
818    pub bright_foreground: Color,
819    pub dim_foreground: Color,
820}
821
822#[derive(Clone, Deserialize, Default)]
823pub struct FeedbackStyle {
824    pub submit_button: Interactive<ContainedText>,
825    pub button_margin: f32,
826    pub info_text: ContainedText,
827}
828
829#[derive(Clone, Deserialize, Default)]
830pub struct ColorScheme {
831    pub name: String,
832    pub is_light: bool,
833
834    pub ramps: RampSet,
835
836    pub lowest: Layer,
837    pub middle: Layer,
838    pub highest: Layer,
839
840    pub popover_shadow: Shadow,
841    pub modal_shadow: Shadow,
842
843    pub players: Vec<Player>,
844}
845
846#[derive(Clone, Deserialize, Default)]
847pub struct Player {
848    pub cursor: Color,
849    pub selection: Color,
850}
851
852#[derive(Clone, Deserialize, Default)]
853pub struct RampSet {
854    pub neutral: Vec<Color>,
855    pub red: Vec<Color>,
856    pub orange: Vec<Color>,
857    pub yellow: Vec<Color>,
858    pub green: Vec<Color>,
859    pub cyan: Vec<Color>,
860    pub blue: Vec<Color>,
861    pub violet: Vec<Color>,
862    pub magenta: Vec<Color>,
863}
864
865#[derive(Clone, Deserialize, Default)]
866pub struct Layer {
867    pub base: StyleSet,
868    pub variant: StyleSet,
869    pub on: StyleSet,
870    pub accent: StyleSet,
871    pub positive: StyleSet,
872    pub warning: StyleSet,
873    pub negative: StyleSet,
874}
875
876#[derive(Clone, Deserialize, Default)]
877pub struct StyleSet {
878    pub default: Style,
879    pub active: Style,
880    pub disabled: Style,
881    pub hovered: Style,
882    pub pressed: Style,
883    pub inverted: Style,
884}
885
886#[derive(Clone, Deserialize, Default)]
887pub struct Style {
888    pub background: Color,
889    pub border: Color,
890    pub foreground: Color,
891}