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