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