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