theme.rs

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