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