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 muted: Color,
 136    pub speaking: Color,
 137    pub screen_share_button: Toggleable<Interactive<IconButton>>,
 138    pub toggle_contacts_button: Toggleable<Interactive<IconButton>>,
 139    pub toggle_microphone_button: Toggleable<Interactive<IconButton>>,
 140    pub toggle_speakers_button: Toggleable<Interactive<IconButton>>,
 141    pub leave_call_button: Interactive<IconButton>,
 142    pub toggle_contacts_badge: ContainerStyle,
 143    pub user_menu: UserMenu,
 144}
 145
 146#[derive(Clone, Deserialize, Default, JsonSchema)]
 147pub struct UserMenu {
 148    pub user_menu_button_online: UserMenuButton,
 149    pub user_menu_button_offline: UserMenuButton,
 150}
 151
 152#[derive(Clone, Deserialize, Default, JsonSchema)]
 153pub struct UserMenuButton {
 154    pub user_menu: Toggleable<Interactive<Icon>>,
 155    pub avatar: AvatarStyle,
 156    pub icon: Icon,
 157}
 158
 159#[derive(Copy, Clone, Deserialize, Default, JsonSchema)]
 160pub struct AvatarStyle {
 161    #[serde(flatten)]
 162    pub image: ImageStyle,
 163    pub outer_width: f32,
 164    pub outer_corner_radius: f32,
 165}
 166
 167#[derive(Deserialize, Default, Clone, JsonSchema)]
 168pub struct Copilot {
 169    pub out_link_icon: Interactive<IconStyle>,
 170    pub modal: ModalStyle,
 171    pub auth: CopilotAuth,
 172}
 173
 174#[derive(Deserialize, Default, Clone, JsonSchema)]
 175pub struct CopilotAuth {
 176    pub content_width: f32,
 177    pub prompting: CopilotAuthPrompting,
 178    pub not_authorized: CopilotAuthNotAuthorized,
 179    pub authorized: CopilotAuthAuthorized,
 180    pub cta_button: ButtonStyle,
 181    pub header: IconStyle,
 182}
 183
 184#[derive(Deserialize, Default, Clone, JsonSchema)]
 185pub struct CopilotAuthPrompting {
 186    pub subheading: ContainedText,
 187    pub hint: ContainedText,
 188    pub device_code: DeviceCode,
 189}
 190
 191#[derive(Deserialize, Default, Clone, JsonSchema)]
 192pub struct DeviceCode {
 193    pub text: TextStyle,
 194    pub cta: ButtonStyle,
 195    pub left: f32,
 196    pub left_container: ContainerStyle,
 197    pub right: f32,
 198    pub right_container: Interactive<ContainerStyle>,
 199}
 200
 201#[derive(Deserialize, Default, Clone, JsonSchema)]
 202pub struct CopilotAuthNotAuthorized {
 203    pub subheading: ContainedText,
 204    pub warning: ContainedText,
 205}
 206
 207#[derive(Deserialize, Default, Clone, JsonSchema)]
 208pub struct CopilotAuthAuthorized {
 209    pub subheading: ContainedText,
 210    pub hint: ContainedText,
 211}
 212
 213#[derive(Deserialize, Default, JsonSchema)]
 214pub struct ContactsPopover {
 215    #[serde(flatten)]
 216    pub container: ContainerStyle,
 217    pub height: f32,
 218    pub width: f32,
 219}
 220
 221#[derive(Deserialize, Default, JsonSchema)]
 222pub struct ContactList {
 223    pub user_query_editor: FieldEditor,
 224    pub user_query_editor_height: f32,
 225    pub add_contact_button: IconButton,
 226    pub header_row: Toggleable<Interactive<ContainedText>>,
 227    pub leave_call: Interactive<ContainedText>,
 228    pub contact_row: Toggleable<Interactive<ContainerStyle>>,
 229    pub row_height: f32,
 230    pub project_row: Toggleable<Interactive<ProjectRow>>,
 231    pub tree_branch: Toggleable<Interactive<TreeBranch>>,
 232    pub contact_avatar: ImageStyle,
 233    pub contact_status_free: ContainerStyle,
 234    pub contact_status_busy: ContainerStyle,
 235    pub contact_username: ContainedText,
 236    pub contact_button: Interactive<IconButton>,
 237    pub contact_button_spacing: f32,
 238    pub disabled_button: IconButton,
 239    pub section_icon_size: f32,
 240    pub calling_indicator: ContainedText,
 241}
 242
 243#[derive(Deserialize, Default, JsonSchema)]
 244pub struct ProjectRow {
 245    #[serde(flatten)]
 246    pub container: ContainerStyle,
 247    pub icon: Icon,
 248    pub name: ContainedText,
 249}
 250
 251#[derive(Deserialize, Default, Clone, Copy, JsonSchema)]
 252pub struct TreeBranch {
 253    pub width: f32,
 254    pub color: Color,
 255}
 256
 257#[derive(Deserialize, Default, JsonSchema)]
 258pub struct ContactFinder {
 259    pub picker: Picker,
 260    pub row_height: f32,
 261    pub contact_avatar: ImageStyle,
 262    pub contact_username: ContainerStyle,
 263    pub contact_button: IconButton,
 264    pub disabled_contact_button: IconButton,
 265}
 266
 267#[derive(Deserialize, Default, JsonSchema)]
 268pub struct DropdownMenu {
 269    #[serde(flatten)]
 270    pub container: ContainerStyle,
 271    pub header: Interactive<DropdownMenuItem>,
 272    pub section_header: ContainedText,
 273    pub item: Toggleable<Interactive<DropdownMenuItem>>,
 274    pub row_height: f32,
 275}
 276
 277#[derive(Deserialize, Default, JsonSchema)]
 278pub struct DropdownMenuItem {
 279    #[serde(flatten)]
 280    pub container: ContainerStyle,
 281    #[serde(flatten)]
 282    pub text: TextStyle,
 283    pub secondary_text: Option<TextStyle>,
 284    #[serde(default)]
 285    pub secondary_text_spacing: f32,
 286}
 287
 288#[derive(Clone, Deserialize, Default, JsonSchema)]
 289pub struct TabBar {
 290    #[serde(flatten)]
 291    pub container: ContainerStyle,
 292    pub pane_button: Toggleable<Interactive<IconButton>>,
 293    pub pane_button_container: ContainerStyle,
 294    pub active_pane: TabStyles,
 295    pub inactive_pane: TabStyles,
 296    pub dragged_tab: Tab,
 297    pub height: f32,
 298}
 299
 300impl TabBar {
 301    pub fn tab_style(&self, pane_active: bool, tab_active: bool) -> &Tab {
 302        let tabs = if pane_active {
 303            &self.active_pane
 304        } else {
 305            &self.inactive_pane
 306        };
 307
 308        if tab_active {
 309            &tabs.active_tab
 310        } else {
 311            &tabs.inactive_tab
 312        }
 313    }
 314}
 315
 316#[derive(Clone, Deserialize, Default, JsonSchema)]
 317pub struct TabStyles {
 318    pub active_tab: Tab,
 319    pub inactive_tab: Tab,
 320}
 321
 322#[derive(Clone, Deserialize, Default, JsonSchema)]
 323pub struct AvatarRibbon {
 324    #[serde(flatten)]
 325    pub container: ContainerStyle,
 326    pub width: f32,
 327    pub height: f32,
 328}
 329
 330#[derive(Clone, Deserialize, Default, JsonSchema)]
 331pub struct OfflineIcon {
 332    #[serde(flatten)]
 333    pub container: ContainerStyle,
 334    pub width: f32,
 335    pub color: Color,
 336}
 337
 338#[derive(Clone, Deserialize, Default, JsonSchema)]
 339pub struct Tab {
 340    pub height: f32,
 341    #[serde(flatten)]
 342    pub container: ContainerStyle,
 343    #[serde(flatten)]
 344    pub label: LabelStyle,
 345    pub description: ContainedText,
 346    pub spacing: f32,
 347    pub close_icon_width: f32,
 348    pub type_icon_width: f32,
 349    pub icon_close: Color,
 350    pub icon_close_active: Color,
 351    pub icon_dirty: Color,
 352    pub icon_conflict: Color,
 353}
 354
 355#[derive(Clone, Deserialize, Default, JsonSchema)]
 356pub struct Toolbar {
 357    #[serde(flatten)]
 358    pub container: ContainerStyle,
 359    pub height: f32,
 360    pub item_spacing: f32,
 361    pub nav_button: Interactive<IconButton>,
 362}
 363
 364#[derive(Clone, Deserialize, Default, JsonSchema)]
 365pub struct Notifications {
 366    #[serde(flatten)]
 367    pub container: ContainerStyle,
 368    pub width: f32,
 369}
 370
 371#[derive(Clone, Deserialize, Default, JsonSchema)]
 372pub struct Search {
 373    #[serde(flatten)]
 374    pub container: ContainerStyle,
 375    pub editor: FindEditor,
 376    pub invalid_editor: ContainerStyle,
 377    pub option_button_group: ContainerStyle,
 378    pub include_exclude_editor: FindEditor,
 379    pub invalid_include_exclude_editor: ContainerStyle,
 380    pub include_exclude_inputs: ContainedText,
 381    pub option_button: Toggleable<Interactive<ContainedText>>,
 382    pub match_background: Color,
 383    pub match_index: ContainedText,
 384    pub results_status: TextStyle,
 385    pub dismiss_button: Interactive<IconButton>,
 386}
 387
 388#[derive(Clone, Deserialize, Default, JsonSchema)]
 389pub struct FindEditor {
 390    #[serde(flatten)]
 391    pub input: FieldEditor,
 392    pub min_width: f32,
 393    pub max_width: f32,
 394}
 395
 396#[derive(Deserialize, Default, JsonSchema)]
 397pub struct StatusBar {
 398    #[serde(flatten)]
 399    pub container: ContainerStyle,
 400    pub height: f32,
 401    pub item_spacing: f32,
 402    pub cursor_position: TextStyle,
 403    pub active_language: Interactive<ContainedText>,
 404    pub auto_update_progress_message: TextStyle,
 405    pub auto_update_done_message: TextStyle,
 406    pub lsp_status: Interactive<StatusBarLspStatus>,
 407    pub panel_buttons: StatusBarPanelButtons,
 408    pub diagnostic_summary: Interactive<StatusBarDiagnosticSummary>,
 409    pub diagnostic_message: Interactive<ContainedText>,
 410}
 411
 412#[derive(Deserialize, Default, JsonSchema)]
 413pub struct StatusBarPanelButtons {
 414    pub group_left: ContainerStyle,
 415    pub group_bottom: ContainerStyle,
 416    pub group_right: ContainerStyle,
 417    pub button: Toggleable<Interactive<PanelButton>>,
 418}
 419
 420#[derive(Deserialize, Default, JsonSchema)]
 421pub struct StatusBarDiagnosticSummary {
 422    pub container_ok: ContainerStyle,
 423    pub container_warning: ContainerStyle,
 424    pub container_error: ContainerStyle,
 425    pub text: TextStyle,
 426    pub icon_color_ok: Color,
 427    pub icon_color_warning: Color,
 428    pub icon_color_error: Color,
 429    pub height: f32,
 430    pub icon_width: f32,
 431    pub icon_spacing: f32,
 432    pub summary_spacing: f32,
 433}
 434
 435#[derive(Deserialize, Default, JsonSchema)]
 436pub struct StatusBarLspStatus {
 437    #[serde(flatten)]
 438    pub container: ContainerStyle,
 439    pub height: f32,
 440    pub icon_spacing: f32,
 441    pub icon_color: Color,
 442    pub icon_width: f32,
 443    pub message: TextStyle,
 444}
 445
 446#[derive(Deserialize, Default, JsonSchema)]
 447pub struct Dock {
 448    pub left: ContainerStyle,
 449    pub bottom: ContainerStyle,
 450    pub right: ContainerStyle,
 451}
 452
 453#[derive(Clone, Deserialize, Default, JsonSchema)]
 454pub struct PanelButton {
 455    #[serde(flatten)]
 456    pub container: ContainerStyle,
 457    pub icon_color: Color,
 458    pub icon_size: f32,
 459    pub label: ContainedText,
 460}
 461
 462#[derive(Deserialize, Default, JsonSchema)]
 463pub struct ProjectPanel {
 464    #[serde(flatten)]
 465    pub container: ContainerStyle,
 466    pub entry: Toggleable<Interactive<ProjectPanelEntry>>,
 467    pub dragged_entry: ProjectPanelEntry,
 468    pub ignored_entry: Toggleable<Interactive<ProjectPanelEntry>>,
 469    pub cut_entry: Toggleable<Interactive<ProjectPanelEntry>>,
 470    pub filename_editor: FieldEditor,
 471    pub indent_width: f32,
 472    pub open_project_button: Interactive<ContainedText>,
 473}
 474
 475#[derive(Clone, Debug, Deserialize, Default, JsonSchema)]
 476pub struct ProjectPanelEntry {
 477    pub height: f32,
 478    #[serde(flatten)]
 479    pub container: ContainerStyle,
 480    pub text: TextStyle,
 481    pub icon_color: Color,
 482    pub icon_size: f32,
 483    pub icon_spacing: f32,
 484    pub status: EntryStatus,
 485}
 486
 487#[derive(Clone, Debug, Deserialize, Default, JsonSchema)]
 488pub struct EntryStatus {
 489    pub git: GitProjectStatus,
 490}
 491
 492#[derive(Clone, Debug, Deserialize, Default, JsonSchema)]
 493pub struct GitProjectStatus {
 494    pub modified: Color,
 495    pub inserted: Color,
 496    pub conflict: Color,
 497}
 498
 499#[derive(Clone, Debug, Deserialize, Default, JsonSchema)]
 500pub struct ContextMenu {
 501    #[serde(flatten)]
 502    pub container: ContainerStyle,
 503    pub item: Toggleable<Interactive<ContextMenuItem>>,
 504    pub keystroke_margin: f32,
 505    pub separator: ContainerStyle,
 506}
 507
 508#[derive(Clone, Debug, Deserialize, Default, JsonSchema)]
 509pub struct ContextMenuItem {
 510    #[serde(flatten)]
 511    pub container: ContainerStyle,
 512    pub label: TextStyle,
 513    pub keystroke: ContainedText,
 514    pub icon_width: f32,
 515    pub icon_spacing: f32,
 516}
 517
 518#[derive(Debug, Deserialize, Default, JsonSchema)]
 519pub struct CommandPalette {
 520    pub key: Toggleable<ContainedLabel>,
 521    pub keystroke_spacing: f32,
 522}
 523
 524#[derive(Deserialize, Default, JsonSchema)]
 525pub struct InviteLink {
 526    #[serde(flatten)]
 527    pub container: ContainerStyle,
 528    #[serde(flatten)]
 529    pub label: LabelStyle,
 530    pub icon: Icon,
 531}
 532
 533#[derive(Deserialize, Clone, Copy, Default, JsonSchema)]
 534pub struct Icon {
 535    #[serde(flatten)]
 536    pub container: ContainerStyle,
 537    pub color: Color,
 538    pub width: f32,
 539}
 540
 541#[derive(Deserialize, Clone, Copy, Default, JsonSchema)]
 542pub struct IconButton {
 543    #[serde(flatten)]
 544    pub container: ContainerStyle,
 545    pub color: Color,
 546    pub icon_width: f32,
 547    pub button_width: f32,
 548}
 549
 550#[derive(Deserialize, Default, JsonSchema)]
 551pub struct ChatMessage {
 552    #[serde(flatten)]
 553    pub container: ContainerStyle,
 554    pub body: TextStyle,
 555    pub sender: ContainedText,
 556    pub timestamp: ContainedText,
 557}
 558
 559#[derive(Deserialize, Default, JsonSchema)]
 560pub struct ChannelSelect {
 561    #[serde(flatten)]
 562    pub container: ContainerStyle,
 563    pub header: ChannelName,
 564    pub item: ChannelName,
 565    pub active_item: ChannelName,
 566    pub hovered_item: ChannelName,
 567    pub hovered_active_item: ChannelName,
 568    pub menu: ContainerStyle,
 569}
 570
 571#[derive(Deserialize, Default, JsonSchema)]
 572pub struct ChannelName {
 573    #[serde(flatten)]
 574    pub container: ContainerStyle,
 575    pub hash: ContainedText,
 576    pub name: TextStyle,
 577}
 578
 579#[derive(Clone, Deserialize, Default, JsonSchema)]
 580pub struct Picker {
 581    #[serde(flatten)]
 582    pub container: ContainerStyle,
 583    pub empty_container: ContainerStyle,
 584    pub input_editor: FieldEditor,
 585    pub empty_input_editor: FieldEditor,
 586    pub no_matches: ContainedLabel,
 587    pub item: Toggleable<Interactive<ContainedLabel>>,
 588}
 589
 590#[derive(Clone, Debug, Deserialize, Default, JsonSchema)]
 591pub struct ContainedText {
 592    #[serde(flatten)]
 593    pub container: ContainerStyle,
 594    #[serde(flatten)]
 595    pub text: TextStyle,
 596}
 597
 598#[derive(Clone, Debug, Deserialize, Default, JsonSchema)]
 599pub struct ContainedLabel {
 600    #[serde(flatten)]
 601    pub container: ContainerStyle,
 602    #[serde(flatten)]
 603    pub label: LabelStyle,
 604}
 605
 606#[derive(Clone, Deserialize, Default, JsonSchema)]
 607pub struct ProjectDiagnostics {
 608    #[serde(flatten)]
 609    pub container: ContainerStyle,
 610    pub empty_message: TextStyle,
 611    pub tab_icon_width: f32,
 612    pub tab_icon_spacing: f32,
 613    pub tab_summary_spacing: f32,
 614}
 615
 616#[derive(Deserialize, Default, JsonSchema)]
 617pub struct ContactNotification {
 618    pub header_avatar: ImageStyle,
 619    pub header_message: ContainedText,
 620    pub header_height: f32,
 621    pub body_message: ContainedText,
 622    pub button: Interactive<ContainedText>,
 623    pub dismiss_button: Interactive<IconButton>,
 624}
 625
 626#[derive(Deserialize, Default, JsonSchema)]
 627pub struct UpdateNotification {
 628    pub message: ContainedText,
 629    pub action_message: Interactive<ContainedText>,
 630    pub dismiss_button: Interactive<IconButton>,
 631}
 632
 633#[derive(Deserialize, Default, JsonSchema)]
 634pub struct MessageNotification {
 635    pub message: ContainedText,
 636    pub action_message: Interactive<ContainedText>,
 637    pub dismiss_button: Interactive<IconButton>,
 638}
 639
 640#[derive(Deserialize, Default, JsonSchema)]
 641pub struct ProjectSharedNotification {
 642    pub window_height: f32,
 643    pub window_width: f32,
 644    #[serde(default)]
 645    pub background: Color,
 646    pub owner_container: ContainerStyle,
 647    pub owner_avatar: ImageStyle,
 648    pub owner_metadata: ContainerStyle,
 649    pub owner_username: ContainedText,
 650    pub message: ContainedText,
 651    pub worktree_roots: ContainedText,
 652    pub button_width: f32,
 653    pub open_button: ContainedText,
 654    pub dismiss_button: ContainedText,
 655}
 656
 657#[derive(Deserialize, Default, JsonSchema)]
 658pub struct IncomingCallNotification {
 659    pub window_height: f32,
 660    pub window_width: f32,
 661    #[serde(default)]
 662    pub background: Color,
 663    pub caller_container: ContainerStyle,
 664    pub caller_avatar: ImageStyle,
 665    pub caller_metadata: ContainerStyle,
 666    pub caller_username: ContainedText,
 667    pub caller_message: ContainedText,
 668    pub worktree_roots: ContainedText,
 669    pub button_width: f32,
 670    pub accept_button: ContainedText,
 671    pub decline_button: ContainedText,
 672}
 673
 674#[derive(Clone, Deserialize, Default, JsonSchema)]
 675pub struct Editor {
 676    pub text_color: Color,
 677    #[serde(default)]
 678    pub background: Color,
 679    pub selection: SelectionStyle,
 680    pub gutter_background: Color,
 681    pub gutter_padding_factor: f32,
 682    pub active_line_background: Color,
 683    pub highlighted_line_background: Color,
 684    pub rename_fade: f32,
 685    pub document_highlight_read_background: Color,
 686    pub document_highlight_write_background: Color,
 687    pub diff: DiffStyle,
 688    pub line_number: Color,
 689    pub line_number_active: Color,
 690    pub guest_selections: Vec<SelectionStyle>,
 691    pub syntax: Arc<SyntaxTheme>,
 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}