theme.rs

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