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