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