theme.rs

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