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