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