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