theme.rs

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