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