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