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