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