1mod theme_registry;
2mod theme_settings;
3pub mod ui;
4
5use gpui::{
6 color::Color,
7 elements::{ContainerStyle, ImageStyle, LabelStyle, Shadow, SvgStyle, TooltipStyle},
8 fonts::{HighlightStyle, TextStyle},
9 platform, AppContext, AssetSource, Border, MouseState,
10};
11use schemars::JsonSchema;
12use serde::{de::DeserializeOwned, Deserialize};
13use serde_json::Value;
14use settings::SettingsStore;
15use std::{collections::HashMap, sync::Arc};
16use ui::{ButtonStyle, CheckboxStyle, IconStyle, ModalStyle};
17
18pub use theme_registry::*;
19pub use theme_settings::*;
20
21pub fn current(cx: &AppContext) -> Arc<Theme> {
22 settings::get::<ThemeSettings>(cx).theme.clone()
23}
24
25pub fn init(source: impl AssetSource, cx: &mut AppContext) {
26 cx.set_global(ThemeRegistry::new(source, cx.font_cache().clone()));
27 settings::register::<ThemeSettings>(cx);
28
29 let mut prev_buffer_font_size = settings::get::<ThemeSettings>(cx).buffer_font_size;
30 cx.observe_global::<SettingsStore, _>(move |cx| {
31 let buffer_font_size = settings::get::<ThemeSettings>(cx).buffer_font_size;
32 if buffer_font_size != prev_buffer_font_size {
33 prev_buffer_font_size = buffer_font_size;
34 reset_font_size(cx);
35 }
36 })
37 .detach();
38}
39
40#[derive(Deserialize, Default, JsonSchema)]
41pub struct Theme {
42 #[serde(default)]
43 pub meta: ThemeMeta,
44 pub workspace: Workspace,
45 pub context_menu: ContextMenu,
46 pub toolbar_dropdown_menu: DropdownMenu,
47 pub copilot: Copilot,
48 pub collab_panel: CollabPanel,
49 pub project_panel: ProjectPanel,
50 pub command_palette: CommandPalette,
51 pub contact_finder: ContactFinder,
52 pub picker: Picker,
53 pub editor: Editor,
54 pub search: Search,
55 pub project_diagnostics: ProjectDiagnostics,
56 pub shared_screen: ContainerStyle,
57 pub contact_notification: ContactNotification,
58 pub update_notification: UpdateNotification,
59 pub simple_message_notification: MessageNotification,
60 pub project_shared_notification: ProjectSharedNotification,
61 pub incoming_call_notification: IncomingCallNotification,
62 pub tooltip: TooltipStyle,
63 pub terminal: TerminalStyle,
64 pub assistant: AssistantStyle,
65 pub feedback: FeedbackStyle,
66 pub welcome: WelcomeStyle,
67 pub titlebar: Titlebar,
68}
69
70#[derive(Deserialize, Default, Clone, JsonSchema)]
71pub struct ThemeMeta {
72 #[serde(skip_deserializing)]
73 pub id: usize,
74 pub name: String,
75 pub is_light: bool,
76}
77
78#[derive(Deserialize, Default, JsonSchema)]
79pub struct Workspace {
80 pub background: Color,
81 pub blank_pane: BlankPaneStyle,
82 pub tab_bar: TabBar,
83 pub pane_divider: Border,
84 pub leader_border_opacity: f32,
85 pub leader_border_width: f32,
86 pub dock: Dock,
87 pub status_bar: StatusBar,
88 pub toolbar: Toolbar,
89 pub breadcrumb_height: f32,
90 pub breadcrumbs: Interactive<ContainedText>,
91 pub disconnected_overlay: ContainedText,
92 pub modal: ContainerStyle,
93 pub zoomed_panel_foreground: ContainerStyle,
94 pub zoomed_pane_foreground: ContainerStyle,
95 pub zoomed_background: ContainerStyle,
96 pub notification: ContainerStyle,
97 pub notifications: Notifications,
98 pub joining_project_avatar: ImageStyle,
99 pub joining_project_message: ContainedText,
100 pub external_location_message: ContainedText,
101 pub drop_target_overlay_color: Color,
102}
103
104#[derive(Clone, Deserialize, Default, JsonSchema)]
105pub struct BlankPaneStyle {
106 pub logo: SvgStyle,
107 pub logo_shadow: SvgStyle,
108 pub logo_container: ContainerStyle,
109 pub keyboard_hints: ContainerStyle,
110 pub keyboard_hint: Interactive<ContainedText>,
111 pub keyboard_hint_width: f32,
112}
113
114#[derive(Clone, Deserialize, Default, JsonSchema)]
115pub struct Titlebar {
116 #[serde(flatten)]
117 pub container: ContainerStyle,
118 pub height: f32,
119 pub menu: TitlebarMenu,
120 pub project_menu_button: Toggleable<Interactive<ContainedText>>,
121 pub project_name_divider: ContainedText,
122 pub git_menu_button: Toggleable<Interactive<ContainedText>>,
123 pub item_spacing: f32,
124 pub face_pile_spacing: f32,
125 pub avatar_ribbon: AvatarRibbon,
126 pub follower_avatar_overlap: f32,
127 pub leader_selection: ContainerStyle,
128 pub offline_icon: OfflineIcon,
129 pub leader_avatar: AvatarStyle,
130 pub follower_avatar: AvatarStyle,
131 pub inactive_avatar_grayscale: bool,
132 pub sign_in_button: Toggleable<Interactive<ContainedText>>,
133 pub outdated_warning: ContainedText,
134 pub share_button: Toggleable<Interactive<ContainedText>>,
135 pub muted: Color,
136 pub speaking: Color,
137 pub screen_share_button: Toggleable<Interactive<IconButton>>,
138 pub toggle_contacts_button: Toggleable<Interactive<IconButton>>,
139 pub toggle_microphone_button: Toggleable<Interactive<IconButton>>,
140 pub toggle_speakers_button: Toggleable<Interactive<IconButton>>,
141 pub leave_call_button: Interactive<IconButton>,
142 pub toggle_contacts_badge: ContainerStyle,
143 pub user_menu: UserMenu,
144}
145
146#[derive(Clone, Deserialize, Default, JsonSchema)]
147pub struct TitlebarMenu {
148 pub width: f32,
149 pub height: f32,
150}
151
152#[derive(Clone, Deserialize, Default, JsonSchema)]
153pub struct UserMenu {
154 pub user_menu_button_online: UserMenuButton,
155 pub user_menu_button_offline: UserMenuButton,
156}
157
158#[derive(Clone, Deserialize, Default, JsonSchema)]
159pub struct UserMenuButton {
160 pub user_menu: Toggleable<Interactive<Icon>>,
161 pub avatar: AvatarStyle,
162 pub icon: Icon,
163}
164
165#[derive(Copy, Clone, Deserialize, Default, JsonSchema)]
166pub struct AvatarStyle {
167 #[serde(flatten)]
168 pub image: ImageStyle,
169 pub outer_width: f32,
170 pub outer_corner_radius: f32,
171}
172
173#[derive(Deserialize, Default, Clone, JsonSchema)]
174pub struct Copilot {
175 pub out_link_icon: Interactive<IconStyle>,
176 pub modal: ModalStyle,
177 pub auth: CopilotAuth,
178}
179
180#[derive(Deserialize, Default, Clone, JsonSchema)]
181pub struct CopilotAuth {
182 pub content_width: f32,
183 pub prompting: CopilotAuthPrompting,
184 pub not_authorized: CopilotAuthNotAuthorized,
185 pub authorized: CopilotAuthAuthorized,
186 pub cta_button: ButtonStyle,
187 pub header: IconStyle,
188}
189
190#[derive(Deserialize, Default, Clone, JsonSchema)]
191pub struct CopilotAuthPrompting {
192 pub subheading: ContainedText,
193 pub hint: ContainedText,
194 pub device_code: DeviceCode,
195}
196
197#[derive(Deserialize, Default, Clone, JsonSchema)]
198pub struct DeviceCode {
199 pub text: TextStyle,
200 pub cta: ButtonStyle,
201 pub left: f32,
202 pub left_container: ContainerStyle,
203 pub right: f32,
204 pub right_container: Interactive<ContainerStyle>,
205}
206
207#[derive(Deserialize, Default, Clone, JsonSchema)]
208pub struct CopilotAuthNotAuthorized {
209 pub subheading: ContainedText,
210 pub warning: ContainedText,
211}
212
213#[derive(Deserialize, Default, Clone, JsonSchema)]
214pub struct CopilotAuthAuthorized {
215 pub subheading: ContainedText,
216 pub hint: ContainedText,
217}
218
219#[derive(Deserialize, Default, JsonSchema)]
220pub struct CollabPanel {
221 #[serde(flatten)]
222 pub container: ContainerStyle,
223 pub channel_hash: Icon,
224 pub channel_modal: ChannelModal,
225 pub user_query_editor: FieldEditor,
226 pub user_query_editor_height: f32,
227 pub leave_call_button: Toggleable<IconButton>,
228 pub add_contact_button: Toggleable<IconButton>,
229 pub add_channel_button: Toggleable<IconButton>,
230 pub header_row: ContainedText,
231 pub subheader_row: Toggleable<Interactive<ContainedText>>,
232 pub leave_call: Interactive<ContainedText>,
233 pub contact_row: Toggleable<Interactive<ContainerStyle>>,
234 pub row_height: f32,
235 pub project_row: Toggleable<Interactive<ProjectRow>>,
236 pub tree_branch: Toggleable<Interactive<TreeBranch>>,
237 pub contact_avatar: ImageStyle,
238 pub contact_status_free: ContainerStyle,
239 pub contact_status_busy: ContainerStyle,
240 pub contact_username: ContainedText,
241 pub contact_button: Interactive<IconButton>,
242 pub contact_button_spacing: f32,
243 pub channel_indent: f32,
244 pub disabled_button: IconButton,
245 pub section_icon_size: f32,
246 pub calling_indicator: ContainedText,
247 pub face_overlap: f32,
248}
249
250#[derive(Deserialize, Default, JsonSchema)]
251pub struct ChannelModal {
252 pub container: ContainerStyle,
253 pub height: f32,
254 pub header: TextStyle,
255 pub mode_button: Toggleable<Interactive<ContainedText>>,
256 pub picker: Picker,
257 pub row_height: f32,
258 pub contact_avatar: ImageStyle,
259 pub contact_username: ContainerStyle,
260 pub remove_member_button: ContainedText,
261 pub cancel_invite_button: ContainedText,
262 pub member_icon: Icon,
263 pub invitee_icon: Icon,
264 pub admin_toggle: ContainedText,
265}
266
267#[derive(Deserialize, Default, JsonSchema)]
268pub struct ProjectRow {
269 #[serde(flatten)]
270 pub container: ContainerStyle,
271 pub icon: Icon,
272 pub name: ContainedText,
273}
274
275#[derive(Deserialize, Default, Clone, Copy, JsonSchema)]
276pub struct TreeBranch {
277 pub width: f32,
278 pub color: Color,
279}
280
281#[derive(Deserialize, Default, JsonSchema)]
282pub struct ContactFinder {
283 pub picker: Picker,
284 pub row_height: f32,
285 pub contact_avatar: ImageStyle,
286 pub contact_username: ContainerStyle,
287 pub contact_button: IconButton,
288 pub disabled_contact_button: IconButton,
289}
290
291#[derive(Deserialize, Default, JsonSchema)]
292pub struct DropdownMenu {
293 #[serde(flatten)]
294 pub container: ContainerStyle,
295 pub header: Interactive<DropdownMenuItem>,
296 pub section_header: ContainedText,
297 pub item: Toggleable<Interactive<DropdownMenuItem>>,
298 pub row_height: f32,
299}
300
301#[derive(Deserialize, Default, JsonSchema)]
302pub struct DropdownMenuItem {
303 #[serde(flatten)]
304 pub container: ContainerStyle,
305 #[serde(flatten)]
306 pub text: TextStyle,
307 pub secondary_text: Option<TextStyle>,
308 #[serde(default)]
309 pub secondary_text_spacing: f32,
310}
311
312#[derive(Clone, Deserialize, Default, JsonSchema)]
313pub struct TabBar {
314 #[serde(flatten)]
315 pub container: ContainerStyle,
316 pub pane_button: Toggleable<Interactive<IconButton>>,
317 pub pane_button_container: ContainerStyle,
318 pub active_pane: TabStyles,
319 pub inactive_pane: TabStyles,
320 pub dragged_tab: Tab,
321 pub height: f32,
322}
323
324impl TabBar {
325 pub fn tab_style(&self, pane_active: bool, tab_active: bool) -> &Tab {
326 let tabs = if pane_active {
327 &self.active_pane
328 } else {
329 &self.inactive_pane
330 };
331
332 if tab_active {
333 &tabs.active_tab
334 } else {
335 &tabs.inactive_tab
336 }
337 }
338}
339
340#[derive(Clone, Deserialize, Default, JsonSchema)]
341pub struct TabStyles {
342 pub active_tab: Tab,
343 pub inactive_tab: Tab,
344}
345
346#[derive(Clone, Deserialize, Default, JsonSchema)]
347pub struct AvatarRibbon {
348 #[serde(flatten)]
349 pub container: ContainerStyle,
350 pub width: f32,
351 pub height: f32,
352}
353
354#[derive(Clone, Deserialize, Default, JsonSchema)]
355pub struct OfflineIcon {
356 #[serde(flatten)]
357 pub container: ContainerStyle,
358 pub width: f32,
359 pub color: Color,
360}
361
362#[derive(Clone, Deserialize, Default, JsonSchema)]
363pub struct Tab {
364 pub height: f32,
365 #[serde(flatten)]
366 pub container: ContainerStyle,
367 #[serde(flatten)]
368 pub label: LabelStyle,
369 pub description: ContainedText,
370 pub spacing: f32,
371 pub close_icon_width: f32,
372 pub type_icon_width: f32,
373 pub icon_close: Color,
374 pub icon_close_active: Color,
375 pub icon_dirty: Color,
376 pub icon_conflict: Color,
377 pub git: GitProjectStatus,
378}
379
380#[derive(Clone, Deserialize, Default, JsonSchema)]
381pub struct Toolbar {
382 #[serde(flatten)]
383 pub container: ContainerStyle,
384 pub height: f32,
385 pub item_spacing: f32,
386 pub nav_button: Interactive<IconButton>,
387}
388
389#[derive(Clone, Deserialize, Default, JsonSchema)]
390pub struct Notifications {
391 #[serde(flatten)]
392 pub container: ContainerStyle,
393 pub width: f32,
394}
395
396#[derive(Clone, Deserialize, Default, JsonSchema)]
397pub struct Search {
398 #[serde(flatten)]
399 pub container: ContainerStyle,
400 pub editor: FindEditor,
401 pub invalid_editor: ContainerStyle,
402 pub option_button_group: ContainerStyle,
403 pub include_exclude_editor: FindEditor,
404 pub invalid_include_exclude_editor: ContainerStyle,
405 pub include_exclude_inputs: ContainedText,
406 pub option_button: Toggleable<Interactive<ContainedText>>,
407 pub action_button: Interactive<ContainedText>,
408 pub match_background: Color,
409 pub match_index: ContainedText,
410 pub results_status: TextStyle,
411 pub dismiss_button: Interactive<IconButton>,
412}
413
414#[derive(Clone, Deserialize, Default, JsonSchema)]
415pub struct FindEditor {
416 #[serde(flatten)]
417 pub input: FieldEditor,
418 pub min_width: f32,
419 pub max_width: f32,
420}
421
422#[derive(Deserialize, Default, JsonSchema)]
423pub struct StatusBar {
424 #[serde(flatten)]
425 pub container: ContainerStyle,
426 pub height: f32,
427 pub item_spacing: f32,
428 pub cursor_position: TextStyle,
429 pub vim_mode_indicator: ContainedText,
430 pub active_language: Interactive<ContainedText>,
431 pub auto_update_progress_message: TextStyle,
432 pub auto_update_done_message: TextStyle,
433 pub lsp_status: Interactive<StatusBarLspStatus>,
434 pub panel_buttons: StatusBarPanelButtons,
435 pub diagnostic_summary: Interactive<StatusBarDiagnosticSummary>,
436 pub diagnostic_message: Interactive<ContainedText>,
437}
438
439#[derive(Deserialize, Default, JsonSchema)]
440pub struct StatusBarPanelButtons {
441 pub group_left: ContainerStyle,
442 pub group_bottom: ContainerStyle,
443 pub group_right: ContainerStyle,
444 pub button: Toggleable<Interactive<PanelButton>>,
445}
446
447#[derive(Deserialize, Default, JsonSchema)]
448pub struct StatusBarDiagnosticSummary {
449 pub container_ok: ContainerStyle,
450 pub container_warning: ContainerStyle,
451 pub container_error: ContainerStyle,
452 pub text: TextStyle,
453 pub icon_color_ok: Color,
454 pub icon_color_warning: Color,
455 pub icon_color_error: Color,
456 pub height: f32,
457 pub icon_width: f32,
458 pub icon_spacing: f32,
459 pub summary_spacing: f32,
460}
461
462#[derive(Deserialize, Default, JsonSchema)]
463pub struct StatusBarLspStatus {
464 #[serde(flatten)]
465 pub container: ContainerStyle,
466 pub height: f32,
467 pub icon_spacing: f32,
468 pub icon_color: Color,
469 pub icon_width: f32,
470 pub message: TextStyle,
471}
472
473#[derive(Deserialize, Default, JsonSchema)]
474pub struct Dock {
475 pub left: ContainerStyle,
476 pub bottom: ContainerStyle,
477 pub right: ContainerStyle,
478}
479
480#[derive(Clone, Deserialize, Default, JsonSchema)]
481pub struct PanelButton {
482 #[serde(flatten)]
483 pub container: ContainerStyle,
484 pub icon_color: Color,
485 pub icon_size: f32,
486 pub label: ContainedText,
487}
488
489#[derive(Deserialize, Default, JsonSchema)]
490pub struct ProjectPanel {
491 #[serde(flatten)]
492 pub container: ContainerStyle,
493 pub entry: Toggleable<Interactive<ProjectPanelEntry>>,
494 pub dragged_entry: ProjectPanelEntry,
495 pub ignored_entry: Toggleable<Interactive<ProjectPanelEntry>>,
496 pub cut_entry: Toggleable<Interactive<ProjectPanelEntry>>,
497 pub filename_editor: FieldEditor,
498 pub indent_width: f32,
499 pub open_project_button: Interactive<ContainedText>,
500}
501
502#[derive(Clone, Debug, Deserialize, Default, JsonSchema)]
503pub struct ProjectPanelEntry {
504 pub height: f32,
505 #[serde(flatten)]
506 pub container: ContainerStyle,
507 pub text: TextStyle,
508 pub icon_size: f32,
509 pub icon_color: Color,
510 pub chevron_color: Color,
511 pub chevron_size: f32,
512 pub icon_spacing: f32,
513 pub status: EntryStatus,
514}
515
516#[derive(Clone, Debug, Deserialize, Default, JsonSchema)]
517pub struct EntryStatus {
518 pub git: GitProjectStatus,
519}
520
521#[derive(Clone, Debug, Deserialize, Default, JsonSchema)]
522pub struct GitProjectStatus {
523 pub modified: Color,
524 pub inserted: Color,
525 pub conflict: Color,
526}
527
528#[derive(Clone, Debug, Deserialize, Default, JsonSchema)]
529pub struct ContextMenu {
530 #[serde(flatten)]
531 pub container: ContainerStyle,
532 pub item: Toggleable<Interactive<ContextMenuItem>>,
533 pub keystroke_margin: f32,
534 pub separator: ContainerStyle,
535}
536
537#[derive(Clone, Debug, Deserialize, Default, JsonSchema)]
538pub struct ContextMenuItem {
539 #[serde(flatten)]
540 pub container: ContainerStyle,
541 pub label: TextStyle,
542 pub keystroke: ContainedText,
543 pub icon_width: f32,
544 pub icon_spacing: f32,
545}
546
547#[derive(Debug, Deserialize, Default, JsonSchema)]
548pub struct CommandPalette {
549 pub key: Toggleable<ContainedLabel>,
550 pub keystroke_spacing: f32,
551}
552
553#[derive(Deserialize, Default, JsonSchema)]
554pub struct InviteLink {
555 #[serde(flatten)]
556 pub container: ContainerStyle,
557 #[serde(flatten)]
558 pub label: LabelStyle,
559 pub icon: Icon,
560}
561
562#[derive(Deserialize, Clone, Copy, Default, JsonSchema)]
563pub struct Icon {
564 #[serde(flatten)]
565 pub container: ContainerStyle,
566 pub color: Color,
567 pub width: f32,
568}
569
570#[derive(Deserialize, Clone, Copy, Default, JsonSchema)]
571pub struct IconButton {
572 #[serde(flatten)]
573 pub container: ContainerStyle,
574 pub color: Color,
575 pub icon_width: f32,
576 pub button_width: f32,
577}
578
579#[derive(Deserialize, Default, JsonSchema)]
580pub struct ChatMessage {
581 #[serde(flatten)]
582 pub container: ContainerStyle,
583 pub body: TextStyle,
584 pub sender: ContainedText,
585 pub timestamp: ContainedText,
586}
587
588#[derive(Deserialize, Default, JsonSchema)]
589pub struct ChannelSelect {
590 #[serde(flatten)]
591 pub container: ContainerStyle,
592 pub header: ChannelName,
593 pub item: ChannelName,
594 pub active_item: ChannelName,
595 pub hovered_item: ChannelName,
596 pub hovered_active_item: ChannelName,
597 pub menu: ContainerStyle,
598}
599
600#[derive(Deserialize, Default, JsonSchema)]
601pub struct ChannelName {
602 #[serde(flatten)]
603 pub container: ContainerStyle,
604 pub hash: ContainedText,
605 pub name: TextStyle,
606}
607
608#[derive(Clone, Deserialize, Default, JsonSchema)]
609pub struct Picker {
610 #[serde(flatten)]
611 pub container: ContainerStyle,
612 pub empty_container: ContainerStyle,
613 pub input_editor: FieldEditor,
614 pub empty_input_editor: FieldEditor,
615 pub no_matches: ContainedLabel,
616 pub item: Toggleable<Interactive<ContainedLabel>>,
617 pub header: ContainedLabel,
618 pub footer: Interactive<ContainedLabel>,
619}
620
621#[derive(Clone, Debug, Deserialize, Default, JsonSchema)]
622pub struct ContainedText {
623 #[serde(flatten)]
624 pub container: ContainerStyle,
625 #[serde(flatten)]
626 pub text: TextStyle,
627}
628
629#[derive(Clone, Debug, Deserialize, Default, JsonSchema)]
630pub struct ContainedLabel {
631 #[serde(flatten)]
632 pub container: ContainerStyle,
633 #[serde(flatten)]
634 pub label: LabelStyle,
635}
636
637#[derive(Clone, Deserialize, Default, JsonSchema)]
638pub struct ProjectDiagnostics {
639 #[serde(flatten)]
640 pub container: ContainerStyle,
641 pub empty_message: TextStyle,
642 pub tab_icon_width: f32,
643 pub tab_icon_spacing: f32,
644 pub tab_summary_spacing: f32,
645}
646
647#[derive(Deserialize, Default, JsonSchema)]
648pub struct ContactNotification {
649 pub header_avatar: ImageStyle,
650 pub header_message: ContainedText,
651 pub header_height: f32,
652 pub body_message: ContainedText,
653 pub button: Interactive<ContainedText>,
654 pub dismiss_button: Interactive<IconButton>,
655}
656
657#[derive(Deserialize, Default, JsonSchema)]
658pub struct UpdateNotification {
659 pub message: ContainedText,
660 pub action_message: Interactive<ContainedText>,
661 pub dismiss_button: Interactive<IconButton>,
662}
663
664#[derive(Deserialize, Default, JsonSchema)]
665pub struct MessageNotification {
666 pub message: ContainedText,
667 pub action_message: Interactive<ContainedText>,
668 pub dismiss_button: Interactive<IconButton>,
669}
670
671#[derive(Deserialize, Default, JsonSchema)]
672pub struct ProjectSharedNotification {
673 pub window_height: f32,
674 pub window_width: f32,
675 #[serde(default)]
676 pub background: Color,
677 pub owner_container: ContainerStyle,
678 pub owner_avatar: ImageStyle,
679 pub owner_metadata: ContainerStyle,
680 pub owner_username: ContainedText,
681 pub message: ContainedText,
682 pub worktree_roots: ContainedText,
683 pub button_width: f32,
684 pub open_button: ContainedText,
685 pub dismiss_button: ContainedText,
686}
687
688#[derive(Deserialize, Default, JsonSchema)]
689pub struct IncomingCallNotification {
690 pub window_height: f32,
691 pub window_width: f32,
692 #[serde(default)]
693 pub background: Color,
694 pub caller_container: ContainerStyle,
695 pub caller_avatar: ImageStyle,
696 pub caller_metadata: ContainerStyle,
697 pub caller_username: ContainedText,
698 pub caller_message: ContainedText,
699 pub worktree_roots: ContainedText,
700 pub button_width: f32,
701 pub accept_button: ContainedText,
702 pub decline_button: ContainedText,
703}
704
705#[derive(Clone, Deserialize, Default, JsonSchema)]
706pub struct Editor {
707 pub text_color: Color,
708 #[serde(default)]
709 pub background: Color,
710 pub selection: SelectionStyle,
711 pub gutter_background: Color,
712 pub gutter_padding_factor: f32,
713 pub active_line_background: Color,
714 pub highlighted_line_background: Color,
715 pub rename_fade: f32,
716 pub document_highlight_read_background: Color,
717 pub document_highlight_write_background: Color,
718 pub diff: DiffStyle,
719 pub wrap_guide: Color,
720 pub active_wrap_guide: Color,
721 pub line_number: Color,
722 pub line_number_active: Color,
723 pub guest_selections: Vec<SelectionStyle>,
724 pub syntax: Arc<SyntaxTheme>,
725 pub hint: HighlightStyle,
726 pub suggestion: HighlightStyle,
727 pub diagnostic_path_header: DiagnosticPathHeader,
728 pub diagnostic_header: DiagnosticHeader,
729 pub error_diagnostic: DiagnosticStyle,
730 pub invalid_error_diagnostic: DiagnosticStyle,
731 pub warning_diagnostic: DiagnosticStyle,
732 pub invalid_warning_diagnostic: DiagnosticStyle,
733 pub information_diagnostic: DiagnosticStyle,
734 pub invalid_information_diagnostic: DiagnosticStyle,
735 pub hint_diagnostic: DiagnosticStyle,
736 pub invalid_hint_diagnostic: DiagnosticStyle,
737 pub autocomplete: AutocompleteStyle,
738 pub code_actions: CodeActions,
739 pub folds: Folds,
740 pub unnecessary_code_fade: f32,
741 pub hover_popover: HoverPopover,
742 pub link_definition: HighlightStyle,
743 pub composition_mark: HighlightStyle,
744 pub jump_icon: Interactive<IconButton>,
745 pub scrollbar: Scrollbar,
746 pub whitespace: Color,
747}
748
749#[derive(Clone, Deserialize, Default, JsonSchema)]
750pub struct Scrollbar {
751 pub track: ContainerStyle,
752 pub thumb: ContainerStyle,
753 pub width: f32,
754 pub min_height_factor: f32,
755 pub git: BufferGitDiffColors,
756 pub selections: Color,
757}
758
759#[derive(Clone, Deserialize, Default, JsonSchema)]
760pub struct BufferGitDiffColors {
761 pub inserted: Color,
762 pub modified: Color,
763 pub deleted: Color,
764}
765
766#[derive(Clone, Deserialize, Default, JsonSchema)]
767pub struct DiagnosticPathHeader {
768 #[serde(flatten)]
769 pub container: ContainerStyle,
770 pub filename: ContainedText,
771 pub path: ContainedText,
772 pub text_scale_factor: f32,
773}
774
775#[derive(Clone, Deserialize, Default, JsonSchema)]
776pub struct DiagnosticHeader {
777 #[serde(flatten)]
778 pub container: ContainerStyle,
779 pub source: ContainedLabel,
780 pub message: ContainedLabel,
781 pub code: ContainedText,
782 pub text_scale_factor: f32,
783 pub icon_width_factor: f32,
784}
785
786#[derive(Clone, Deserialize, Default, JsonSchema)]
787pub struct DiagnosticStyle {
788 pub message: LabelStyle,
789 #[serde(default)]
790 pub header: ContainerStyle,
791 pub text_scale_factor: f32,
792}
793
794#[derive(Clone, Deserialize, Default, JsonSchema)]
795pub struct AutocompleteStyle {
796 #[serde(flatten)]
797 pub container: ContainerStyle,
798 pub item: ContainerStyle,
799 pub selected_item: ContainerStyle,
800 pub hovered_item: ContainerStyle,
801 pub match_highlight: HighlightStyle,
802}
803
804#[derive(Clone, Copy, Default, Deserialize, JsonSchema)]
805pub struct SelectionStyle {
806 pub cursor: Color,
807 pub selection: Color,
808}
809
810#[derive(Clone, Deserialize, Default, JsonSchema)]
811pub struct FieldEditor {
812 #[serde(flatten)]
813 pub container: ContainerStyle,
814 pub text: TextStyle,
815 #[serde(default)]
816 pub placeholder_text: Option<TextStyle>,
817 pub selection: SelectionStyle,
818}
819
820#[derive(Clone, Deserialize, Default, JsonSchema)]
821pub struct InteractiveColor {
822 pub color: Color,
823}
824
825#[derive(Clone, Deserialize, Default, JsonSchema)]
826pub struct CodeActions {
827 #[serde(default)]
828 pub indicator: Toggleable<Interactive<InteractiveColor>>,
829 pub vertical_scale: f32,
830}
831
832#[derive(Clone, Deserialize, Default, JsonSchema)]
833pub struct Folds {
834 pub indicator: Toggleable<Interactive<InteractiveColor>>,
835 pub ellipses: FoldEllipses,
836 pub fold_background: Color,
837 pub icon_margin_scale: f32,
838 pub folded_icon: String,
839 pub foldable_icon: String,
840}
841
842#[derive(Clone, Deserialize, Default, JsonSchema)]
843pub struct FoldEllipses {
844 pub text_color: Color,
845 pub background: Interactive<InteractiveColor>,
846 pub corner_radius_factor: f32,
847}
848
849#[derive(Clone, Deserialize, Default, JsonSchema)]
850pub struct DiffStyle {
851 pub inserted: Color,
852 pub modified: Color,
853 pub deleted: Color,
854 pub removed_width_em: f32,
855 pub width_em: f32,
856 pub corner_radius: f32,
857}
858
859#[derive(Debug, Default, Clone, Copy, JsonSchema)]
860pub struct Interactive<T> {
861 pub default: T,
862 pub hovered: Option<T>,
863 pub clicked: Option<T>,
864 pub disabled: Option<T>,
865}
866
867#[derive(Clone, Copy, Debug, Default, Deserialize, JsonSchema)]
868pub struct Toggleable<T> {
869 active: T,
870 inactive: T,
871}
872
873impl<T> Toggleable<T> {
874 pub fn new(active: T, inactive: T) -> Self {
875 Self { active, inactive }
876 }
877 pub fn in_state(&self, active: bool) -> &T {
878 if active {
879 &self.active
880 } else {
881 &self.inactive
882 }
883 }
884 pub fn active_state(&self) -> &T {
885 self.in_state(true)
886 }
887 pub fn inactive_state(&self) -> &T {
888 self.in_state(false)
889 }
890}
891
892impl<T> Interactive<T> {
893 pub fn style_for(&self, state: &mut MouseState) -> &T {
894 if state.clicked() == Some(platform::MouseButton::Left) && self.clicked.is_some() {
895 self.clicked.as_ref().unwrap()
896 } else if state.hovered() {
897 self.hovered.as_ref().unwrap_or(&self.default)
898 } else {
899 &self.default
900 }
901 }
902 pub fn disabled_style(&self) -> &T {
903 self.disabled.as_ref().unwrap_or(&self.default)
904 }
905}
906
907impl<T> Toggleable<Interactive<T>> {
908 pub fn style_for(&self, active: bool, state: &mut MouseState) -> &T {
909 self.in_state(active).style_for(state)
910 }
911
912 pub fn default_style(&self) -> &T {
913 &self.inactive.default
914 }
915}
916
917impl<'de, T: DeserializeOwned> Deserialize<'de> for Interactive<T> {
918 fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
919 where
920 D: serde::Deserializer<'de>,
921 {
922 #[derive(Deserialize)]
923 struct Helper {
924 default: Value,
925 hovered: Option<Value>,
926 clicked: Option<Value>,
927 disabled: Option<Value>,
928 }
929
930 let json = Helper::deserialize(deserializer)?;
931
932 let deserialize_state = |state_json: Option<Value>| -> Result<Option<T>, D::Error> {
933 if let Some(mut state_json) = state_json {
934 if let Value::Object(state_json) = &mut state_json {
935 if let Value::Object(default) = &json.default {
936 for (key, value) in default {
937 if !state_json.contains_key(key) {
938 state_json.insert(key.clone(), value.clone());
939 }
940 }
941 }
942 }
943 Ok(Some(
944 serde_json::from_value::<T>(state_json).map_err(serde::de::Error::custom)?,
945 ))
946 } else {
947 Ok(None)
948 }
949 };
950
951 let hovered = deserialize_state(json.hovered)?;
952 let clicked = deserialize_state(json.clicked)?;
953 let disabled = deserialize_state(json.disabled)?;
954 let default = serde_json::from_value(json.default).map_err(serde::de::Error::custom)?;
955
956 Ok(Interactive {
957 default,
958 hovered,
959 clicked,
960 disabled,
961 })
962 }
963}
964
965impl Editor {
966 pub fn replica_selection_style(&self, replica_id: u16) -> &SelectionStyle {
967 let style_ix = replica_id as usize % (self.guest_selections.len() + 1);
968 if style_ix == 0 {
969 &self.selection
970 } else {
971 &self.guest_selections[style_ix - 1]
972 }
973 }
974}
975
976#[derive(Default, JsonSchema)]
977pub struct SyntaxTheme {
978 pub highlights: Vec<(String, HighlightStyle)>,
979}
980
981impl SyntaxTheme {
982 pub fn new(highlights: Vec<(String, HighlightStyle)>) -> Self {
983 Self { highlights }
984 }
985}
986
987impl<'de> Deserialize<'de> for SyntaxTheme {
988 fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
989 where
990 D: serde::Deserializer<'de>,
991 {
992 let syntax_data: HashMap<String, HighlightStyle> = Deserialize::deserialize(deserializer)?;
993
994 let mut result = Self::new(Vec::new());
995 for (key, style) in syntax_data {
996 match result
997 .highlights
998 .binary_search_by(|(needle, _)| needle.cmp(&key))
999 {
1000 Ok(i) | Err(i) => {
1001 result.highlights.insert(i, (key, style));
1002 }
1003 }
1004 }
1005
1006 Ok(result)
1007 }
1008}
1009
1010#[derive(Clone, Deserialize, Default, JsonSchema)]
1011pub struct HoverPopover {
1012 pub container: ContainerStyle,
1013 pub info_container: ContainerStyle,
1014 pub warning_container: ContainerStyle,
1015 pub error_container: ContainerStyle,
1016 pub block_style: ContainerStyle,
1017 pub prose: TextStyle,
1018 pub diagnostic_source_highlight: HighlightStyle,
1019 pub highlight: Color,
1020}
1021
1022#[derive(Clone, Deserialize, Default, JsonSchema)]
1023pub struct TerminalStyle {
1024 pub black: Color,
1025 pub red: Color,
1026 pub green: Color,
1027 pub yellow: Color,
1028 pub blue: Color,
1029 pub magenta: Color,
1030 pub cyan: Color,
1031 pub white: Color,
1032 pub bright_black: Color,
1033 pub bright_red: Color,
1034 pub bright_green: Color,
1035 pub bright_yellow: Color,
1036 pub bright_blue: Color,
1037 pub bright_magenta: Color,
1038 pub bright_cyan: Color,
1039 pub bright_white: Color,
1040 pub foreground: Color,
1041 pub background: Color,
1042 pub modal_background: Color,
1043 pub cursor: Color,
1044 pub dim_black: Color,
1045 pub dim_red: Color,
1046 pub dim_green: Color,
1047 pub dim_yellow: Color,
1048 pub dim_blue: Color,
1049 pub dim_magenta: Color,
1050 pub dim_cyan: Color,
1051 pub dim_white: Color,
1052 pub bright_foreground: Color,
1053 pub dim_foreground: Color,
1054}
1055
1056#[derive(Clone, Deserialize, Default, JsonSchema)]
1057pub struct AssistantStyle {
1058 pub container: ContainerStyle,
1059 pub hamburger_button: Interactive<IconStyle>,
1060 pub split_button: Interactive<IconStyle>,
1061 pub assist_button: Interactive<IconStyle>,
1062 pub quote_button: Interactive<IconStyle>,
1063 pub zoom_in_button: Interactive<IconStyle>,
1064 pub zoom_out_button: Interactive<IconStyle>,
1065 pub plus_button: Interactive<IconStyle>,
1066 pub title: ContainedText,
1067 pub message_header: ContainerStyle,
1068 pub sent_at: ContainedText,
1069 pub user_sender: Interactive<ContainedText>,
1070 pub assistant_sender: Interactive<ContainedText>,
1071 pub system_sender: Interactive<ContainedText>,
1072 pub model: Interactive<ContainedText>,
1073 pub remaining_tokens: ContainedText,
1074 pub low_remaining_tokens: ContainedText,
1075 pub no_remaining_tokens: ContainedText,
1076 pub error_icon: Icon,
1077 pub api_key_editor: FieldEditor,
1078 pub api_key_prompt: ContainedText,
1079 pub saved_conversation: SavedConversation,
1080}
1081
1082#[derive(Clone, Deserialize, Default, JsonSchema)]
1083pub struct Contained<T> {
1084 container: ContainerStyle,
1085 contained: T,
1086}
1087
1088#[derive(Clone, Deserialize, Default, JsonSchema)]
1089pub struct SavedConversation {
1090 pub container: Interactive<ContainerStyle>,
1091 pub saved_at: ContainedText,
1092 pub title: ContainedText,
1093}
1094
1095#[derive(Clone, Deserialize, Default, JsonSchema)]
1096pub struct FeedbackStyle {
1097 pub submit_button: Interactive<ContainedText>,
1098 pub button_margin: f32,
1099 pub info_text_default: ContainedText,
1100 pub link_text_default: ContainedText,
1101 pub link_text_hover: ContainedText,
1102}
1103
1104#[derive(Clone, Deserialize, Default, JsonSchema)]
1105pub struct WelcomeStyle {
1106 pub page_width: f32,
1107 pub logo: SvgStyle,
1108 pub logo_subheading: ContainedText,
1109 pub usage_note: ContainedText,
1110 pub checkbox: CheckboxStyle,
1111 pub checkbox_container: ContainerStyle,
1112 pub button: Interactive<ContainedText>,
1113 pub button_group: ContainerStyle,
1114 pub heading_group: ContainerStyle,
1115 pub checkbox_group: ContainerStyle,
1116}
1117
1118#[derive(Clone, Deserialize, Default, JsonSchema)]
1119pub struct ColorScheme {
1120 pub name: String,
1121 pub is_light: bool,
1122 pub ramps: RampSet,
1123 pub lowest: Layer,
1124 pub middle: Layer,
1125 pub highest: Layer,
1126
1127 pub popover_shadow: Shadow,
1128 pub modal_shadow: Shadow,
1129
1130 pub players: Vec<Player>,
1131}
1132
1133#[derive(Clone, Deserialize, Default, JsonSchema)]
1134pub struct Player {
1135 pub cursor: Color,
1136 pub selection: Color,
1137}
1138
1139#[derive(Clone, Deserialize, Default, JsonSchema)]
1140pub struct RampSet {
1141 pub neutral: Vec<Color>,
1142 pub red: Vec<Color>,
1143 pub orange: Vec<Color>,
1144 pub yellow: Vec<Color>,
1145 pub green: Vec<Color>,
1146 pub cyan: Vec<Color>,
1147 pub blue: Vec<Color>,
1148 pub violet: Vec<Color>,
1149 pub magenta: Vec<Color>,
1150}
1151
1152#[derive(Clone, Deserialize, Default, JsonSchema)]
1153pub struct Layer {
1154 pub base: StyleSet,
1155 pub variant: StyleSet,
1156 pub on: StyleSet,
1157 pub accent: StyleSet,
1158 pub positive: StyleSet,
1159 pub warning: StyleSet,
1160 pub negative: StyleSet,
1161}
1162
1163#[derive(Clone, Deserialize, Default, JsonSchema)]
1164pub struct StyleSet {
1165 pub default: Style,
1166 pub active: Style,
1167 pub disabled: Style,
1168 pub hovered: Style,
1169 pub pressed: Style,
1170 pub inverted: Style,
1171}
1172
1173#[derive(Clone, Deserialize, Default, JsonSchema)]
1174pub struct Style {
1175 pub background: Color,
1176 pub border: Color,
1177 pub foreground: Color,
1178}