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