schema.rs

  1#![allow(missing_docs)]
  2
  3use gpui::{HighlightStyle, Hsla};
  4use palette::FromColor;
  5use schemars::JsonSchema;
  6use serde::{Deserialize, Serialize};
  7use settings::IntoGpui;
  8pub use settings::{
  9    FontStyleContent, HighlightStyleContent, StatusColorsContent, ThemeColorsContent,
 10    ThemeStyleContent,
 11};
 12pub use settings::{FontWeightContent, WindowBackgroundContent};
 13
 14use theme::{StatusColorsRefinement, ThemeColorsRefinement};
 15
 16/// The content of a serialized theme family.
 17#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
 18pub struct ThemeFamilyContent {
 19    pub name: String,
 20    pub author: String,
 21    pub themes: Vec<ThemeContent>,
 22}
 23
 24/// The content of a serialized theme.
 25#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
 26pub struct ThemeContent {
 27    pub name: String,
 28    pub appearance: theme::AppearanceContent,
 29    pub style: settings::ThemeStyleContent,
 30}
 31
 32/// Returns the syntax style overrides in the [`ThemeContent`].
 33pub fn syntax_overrides(this: &settings::ThemeStyleContent) -> Vec<(String, HighlightStyle)> {
 34    this.syntax
 35        .iter()
 36        .map(|(key, style)| {
 37            (
 38                key.clone(),
 39                HighlightStyle {
 40                    color: style
 41                        .color
 42                        .as_ref()
 43                        .and_then(|color| theme::try_parse_color(color).ok()),
 44                    background_color: style
 45                        .background_color
 46                        .as_ref()
 47                        .and_then(|color| theme::try_parse_color(color).ok()),
 48                    font_style: style.font_style.map(|s| s.into_gpui()),
 49                    font_weight: style.font_weight.map(|w| w.into_gpui()),
 50                    ..Default::default()
 51                },
 52            )
 53        })
 54        .collect()
 55}
 56
 57pub fn status_colors_refinement(colors: &settings::StatusColorsContent) -> StatusColorsRefinement {
 58    StatusColorsRefinement {
 59        conflict: colors
 60            .conflict
 61            .as_ref()
 62            .and_then(|color| try_parse_color(color).ok()),
 63        conflict_background: colors
 64            .conflict_background
 65            .as_ref()
 66            .and_then(|color| try_parse_color(color).ok()),
 67        conflict_border: colors
 68            .conflict_border
 69            .as_ref()
 70            .and_then(|color| try_parse_color(color).ok()),
 71        created: colors
 72            .created
 73            .as_ref()
 74            .and_then(|color| try_parse_color(color).ok()),
 75        created_background: colors
 76            .created_background
 77            .as_ref()
 78            .and_then(|color| try_parse_color(color).ok()),
 79        created_border: colors
 80            .created_border
 81            .as_ref()
 82            .and_then(|color| try_parse_color(color).ok()),
 83        deleted: colors
 84            .deleted
 85            .as_ref()
 86            .and_then(|color| try_parse_color(color).ok()),
 87        deleted_background: colors
 88            .deleted_background
 89            .as_ref()
 90            .and_then(|color| try_parse_color(color).ok()),
 91        deleted_border: colors
 92            .deleted_border
 93            .as_ref()
 94            .and_then(|color| try_parse_color(color).ok()),
 95        error: colors
 96            .error
 97            .as_ref()
 98            .and_then(|color| try_parse_color(color).ok()),
 99        error_background: colors
100            .error_background
101            .as_ref()
102            .and_then(|color| try_parse_color(color).ok()),
103        error_border: colors
104            .error_border
105            .as_ref()
106            .and_then(|color| try_parse_color(color).ok()),
107        hidden: colors
108            .hidden
109            .as_ref()
110            .and_then(|color| try_parse_color(color).ok()),
111        hidden_background: colors
112            .hidden_background
113            .as_ref()
114            .and_then(|color| try_parse_color(color).ok()),
115        hidden_border: colors
116            .hidden_border
117            .as_ref()
118            .and_then(|color| try_parse_color(color).ok()),
119        hint: colors
120            .hint
121            .as_ref()
122            .and_then(|color| try_parse_color(color).ok()),
123        hint_background: colors
124            .hint_background
125            .as_ref()
126            .and_then(|color| try_parse_color(color).ok()),
127        hint_border: colors
128            .hint_border
129            .as_ref()
130            .and_then(|color| try_parse_color(color).ok()),
131        ignored: colors
132            .ignored
133            .as_ref()
134            .and_then(|color| try_parse_color(color).ok()),
135        ignored_background: colors
136            .ignored_background
137            .as_ref()
138            .and_then(|color| try_parse_color(color).ok()),
139        ignored_border: colors
140            .ignored_border
141            .as_ref()
142            .and_then(|color| try_parse_color(color).ok()),
143        info: colors
144            .info
145            .as_ref()
146            .and_then(|color| try_parse_color(color).ok()),
147        info_background: colors
148            .info_background
149            .as_ref()
150            .and_then(|color| try_parse_color(color).ok()),
151        info_border: colors
152            .info_border
153            .as_ref()
154            .and_then(|color| try_parse_color(color).ok()),
155        modified: colors
156            .modified
157            .as_ref()
158            .and_then(|color| try_parse_color(color).ok()),
159        modified_background: colors
160            .modified_background
161            .as_ref()
162            .and_then(|color| try_parse_color(color).ok()),
163        modified_border: colors
164            .modified_border
165            .as_ref()
166            .and_then(|color| try_parse_color(color).ok()),
167        predictive: colors
168            .predictive
169            .as_ref()
170            .and_then(|color| try_parse_color(color).ok()),
171        predictive_background: colors
172            .predictive_background
173            .as_ref()
174            .and_then(|color| try_parse_color(color).ok()),
175        predictive_border: colors
176            .predictive_border
177            .as_ref()
178            .and_then(|color| try_parse_color(color).ok()),
179        renamed: colors
180            .renamed
181            .as_ref()
182            .and_then(|color| try_parse_color(color).ok()),
183        renamed_background: colors
184            .renamed_background
185            .as_ref()
186            .and_then(|color| try_parse_color(color).ok()),
187        renamed_border: colors
188            .renamed_border
189            .as_ref()
190            .and_then(|color| try_parse_color(color).ok()),
191        success: colors
192            .success
193            .as_ref()
194            .and_then(|color| try_parse_color(color).ok()),
195        success_background: colors
196            .success_background
197            .as_ref()
198            .and_then(|color| try_parse_color(color).ok()),
199        success_border: colors
200            .success_border
201            .as_ref()
202            .and_then(|color| try_parse_color(color).ok()),
203        unreachable: colors
204            .unreachable
205            .as_ref()
206            .and_then(|color| try_parse_color(color).ok()),
207        unreachable_background: colors
208            .unreachable_background
209            .as_ref()
210            .and_then(|color| try_parse_color(color).ok()),
211        unreachable_border: colors
212            .unreachable_border
213            .as_ref()
214            .and_then(|color| try_parse_color(color).ok()),
215        warning: colors
216            .warning
217            .as_ref()
218            .and_then(|color| try_parse_color(color).ok()),
219        warning_background: colors
220            .warning_background
221            .as_ref()
222            .and_then(|color| try_parse_color(color).ok()),
223        warning_border: colors
224            .warning_border
225            .as_ref()
226            .and_then(|color| try_parse_color(color).ok()),
227    }
228}
229
230pub fn theme_colors_refinement(
231    this: &settings::ThemeColorsContent,
232    status_colors: &StatusColorsRefinement,
233) -> ThemeColorsRefinement {
234    let border = this
235        .border
236        .as_ref()
237        .and_then(|color| try_parse_color(color).ok());
238    let editor_document_highlight_read_background = this
239        .editor_document_highlight_read_background
240        .as_ref()
241        .and_then(|color| try_parse_color(color).ok());
242    let scrollbar_thumb_background = this
243        .scrollbar_thumb_background
244        .as_ref()
245        .and_then(|color| try_parse_color(color).ok())
246        .or_else(|| {
247            this.deprecated_scrollbar_thumb_background
248                .as_ref()
249                .and_then(|color| try_parse_color(color).ok())
250        });
251    let scrollbar_thumb_hover_background = this
252        .scrollbar_thumb_hover_background
253        .as_ref()
254        .and_then(|color| try_parse_color(color).ok());
255    let scrollbar_thumb_active_background = this
256        .scrollbar_thumb_active_background
257        .as_ref()
258        .and_then(|color| try_parse_color(color).ok())
259        .or(scrollbar_thumb_background);
260    let scrollbar_thumb_border = this
261        .scrollbar_thumb_border
262        .as_ref()
263        .and_then(|color| try_parse_color(color).ok());
264    let element_hover = this
265        .element_hover
266        .as_ref()
267        .and_then(|color| try_parse_color(color).ok());
268    let panel_background = this
269        .panel_background
270        .as_ref()
271        .and_then(|color| try_parse_color(color).ok());
272    let search_match_background = this
273        .search_match_background
274        .as_ref()
275        .and_then(|color| try_parse_color(color).ok());
276    let search_active_match_background = this
277        .search_active_match_background
278        .as_ref()
279        .and_then(|color| try_parse_color(color).ok())
280        .or(search_match_background);
281    ThemeColorsRefinement {
282        border,
283        border_variant: this
284            .border_variant
285            .as_ref()
286            .and_then(|color| try_parse_color(color).ok()),
287        border_focused: this
288            .border_focused
289            .as_ref()
290            .and_then(|color| try_parse_color(color).ok()),
291        border_selected: this
292            .border_selected
293            .as_ref()
294            .and_then(|color| try_parse_color(color).ok()),
295        border_transparent: this
296            .border_transparent
297            .as_ref()
298            .and_then(|color| try_parse_color(color).ok()),
299        border_disabled: this
300            .border_disabled
301            .as_ref()
302            .and_then(|color| try_parse_color(color).ok()),
303        elevated_surface_background: this
304            .elevated_surface_background
305            .as_ref()
306            .and_then(|color| try_parse_color(color).ok()),
307        surface_background: this
308            .surface_background
309            .as_ref()
310            .and_then(|color| try_parse_color(color).ok()),
311        background: this
312            .background
313            .as_ref()
314            .and_then(|color| try_parse_color(color).ok()),
315        element_background: this
316            .element_background
317            .as_ref()
318            .and_then(|color| try_parse_color(color).ok()),
319        element_hover,
320        element_active: this
321            .element_active
322            .as_ref()
323            .and_then(|color| try_parse_color(color).ok()),
324        element_selected: this
325            .element_selected
326            .as_ref()
327            .and_then(|color| try_parse_color(color).ok()),
328        element_disabled: this
329            .element_disabled
330            .as_ref()
331            .and_then(|color| try_parse_color(color).ok()),
332        element_selection_background: this
333            .element_selection_background
334            .as_ref()
335            .and_then(|color| try_parse_color(color).ok()),
336        drop_target_background: this
337            .drop_target_background
338            .as_ref()
339            .and_then(|color| try_parse_color(color).ok()),
340        drop_target_border: this
341            .drop_target_border
342            .as_ref()
343            .and_then(|color| try_parse_color(color).ok()),
344        ghost_element_background: this
345            .ghost_element_background
346            .as_ref()
347            .and_then(|color| try_parse_color(color).ok()),
348        ghost_element_hover: this
349            .ghost_element_hover
350            .as_ref()
351            .and_then(|color| try_parse_color(color).ok()),
352        ghost_element_active: this
353            .ghost_element_active
354            .as_ref()
355            .and_then(|color| try_parse_color(color).ok()),
356        ghost_element_selected: this
357            .ghost_element_selected
358            .as_ref()
359            .and_then(|color| try_parse_color(color).ok()),
360        ghost_element_disabled: this
361            .ghost_element_disabled
362            .as_ref()
363            .and_then(|color| try_parse_color(color).ok()),
364        text: this
365            .text
366            .as_ref()
367            .and_then(|color| try_parse_color(color).ok()),
368        text_muted: this
369            .text_muted
370            .as_ref()
371            .and_then(|color| try_parse_color(color).ok()),
372        text_placeholder: this
373            .text_placeholder
374            .as_ref()
375            .and_then(|color| try_parse_color(color).ok()),
376        text_disabled: this
377            .text_disabled
378            .as_ref()
379            .and_then(|color| try_parse_color(color).ok()),
380        text_accent: this
381            .text_accent
382            .as_ref()
383            .and_then(|color| try_parse_color(color).ok()),
384        icon: this
385            .icon
386            .as_ref()
387            .and_then(|color| try_parse_color(color).ok()),
388        icon_muted: this
389            .icon_muted
390            .as_ref()
391            .and_then(|color| try_parse_color(color).ok()),
392        icon_disabled: this
393            .icon_disabled
394            .as_ref()
395            .and_then(|color| try_parse_color(color).ok()),
396        icon_placeholder: this
397            .icon_placeholder
398            .as_ref()
399            .and_then(|color| try_parse_color(color).ok()),
400        icon_accent: this
401            .icon_accent
402            .as_ref()
403            .and_then(|color| try_parse_color(color).ok()),
404        debugger_accent: this
405            .debugger_accent
406            .as_ref()
407            .and_then(|color| try_parse_color(color).ok()),
408        status_bar_background: this
409            .status_bar_background
410            .as_ref()
411            .and_then(|color| try_parse_color(color).ok()),
412        title_bar_background: this
413            .title_bar_background
414            .as_ref()
415            .and_then(|color| try_parse_color(color).ok()),
416        title_bar_inactive_background: this
417            .title_bar_inactive_background
418            .as_ref()
419            .and_then(|color| try_parse_color(color).ok()),
420        toolbar_background: this
421            .toolbar_background
422            .as_ref()
423            .and_then(|color| try_parse_color(color).ok()),
424        tab_bar_background: this
425            .tab_bar_background
426            .as_ref()
427            .and_then(|color| try_parse_color(color).ok()),
428        tab_inactive_background: this
429            .tab_inactive_background
430            .as_ref()
431            .and_then(|color| try_parse_color(color).ok()),
432        tab_active_background: this
433            .tab_active_background
434            .as_ref()
435            .and_then(|color| try_parse_color(color).ok()),
436        search_match_background,
437        search_active_match_background,
438        panel_background,
439        panel_focused_border: this
440            .panel_focused_border
441            .as_ref()
442            .and_then(|color| try_parse_color(color).ok()),
443        panel_indent_guide: this
444            .panel_indent_guide
445            .as_ref()
446            .and_then(|color| try_parse_color(color).ok()),
447        panel_indent_guide_hover: this
448            .panel_indent_guide_hover
449            .as_ref()
450            .and_then(|color| try_parse_color(color).ok()),
451        panel_indent_guide_active: this
452            .panel_indent_guide_active
453            .as_ref()
454            .and_then(|color| try_parse_color(color).ok()),
455        panel_overlay_background: this
456            .panel_overlay_background
457            .as_ref()
458            .and_then(|color| try_parse_color(color).ok())
459            .or(panel_background.map(ensure_opaque)),
460        panel_overlay_hover: this
461            .panel_overlay_hover
462            .as_ref()
463            .and_then(|color| try_parse_color(color).ok())
464            .or(panel_background
465                .zip(element_hover)
466                .map(|(panel_bg, hover_bg)| panel_bg.blend(hover_bg))
467                .map(ensure_opaque)),
468        pane_focused_border: this
469            .pane_focused_border
470            .as_ref()
471            .and_then(|color| try_parse_color(color).ok()),
472        pane_group_border: this
473            .pane_group_border
474            .as_ref()
475            .and_then(|color| try_parse_color(color).ok())
476            .or(border),
477        scrollbar_thumb_background,
478        scrollbar_thumb_hover_background,
479        scrollbar_thumb_active_background,
480        scrollbar_thumb_border,
481        scrollbar_track_background: this
482            .scrollbar_track_background
483            .as_ref()
484            .and_then(|color| try_parse_color(color).ok()),
485        scrollbar_track_border: this
486            .scrollbar_track_border
487            .as_ref()
488            .and_then(|color| try_parse_color(color).ok()),
489        minimap_thumb_background: this
490            .minimap_thumb_background
491            .as_ref()
492            .and_then(|color| try_parse_color(color).ok())
493            .or(scrollbar_thumb_background.map(ensure_non_opaque)),
494        minimap_thumb_hover_background: this
495            .minimap_thumb_hover_background
496            .as_ref()
497            .and_then(|color| try_parse_color(color).ok())
498            .or(scrollbar_thumb_hover_background.map(ensure_non_opaque)),
499        minimap_thumb_active_background: this
500            .minimap_thumb_active_background
501            .as_ref()
502            .and_then(|color| try_parse_color(color).ok())
503            .or(scrollbar_thumb_active_background.map(ensure_non_opaque)),
504        minimap_thumb_border: this
505            .minimap_thumb_border
506            .as_ref()
507            .and_then(|color| try_parse_color(color).ok())
508            .or(scrollbar_thumb_border),
509        editor_foreground: this
510            .editor_foreground
511            .as_ref()
512            .and_then(|color| try_parse_color(color).ok()),
513        editor_background: this
514            .editor_background
515            .as_ref()
516            .and_then(|color| try_parse_color(color).ok()),
517        editor_gutter_background: this
518            .editor_gutter_background
519            .as_ref()
520            .and_then(|color| try_parse_color(color).ok()),
521        editor_subheader_background: this
522            .editor_subheader_background
523            .as_ref()
524            .and_then(|color| try_parse_color(color).ok()),
525        editor_active_line_background: this
526            .editor_active_line_background
527            .as_ref()
528            .and_then(|color| try_parse_color(color).ok()),
529        editor_highlighted_line_background: this
530            .editor_highlighted_line_background
531            .as_ref()
532            .and_then(|color| try_parse_color(color).ok()),
533        editor_debugger_active_line_background: this
534            .editor_debugger_active_line_background
535            .as_ref()
536            .and_then(|color| try_parse_color(color).ok()),
537        editor_line_number: this
538            .editor_line_number
539            .as_ref()
540            .and_then(|color| try_parse_color(color).ok()),
541        editor_hover_line_number: this
542            .editor_hover_line_number
543            .as_ref()
544            .and_then(|color| try_parse_color(color).ok()),
545        editor_active_line_number: this
546            .editor_active_line_number
547            .as_ref()
548            .and_then(|color| try_parse_color(color).ok()),
549        editor_invisible: this
550            .editor_invisible
551            .as_ref()
552            .and_then(|color| try_parse_color(color).ok()),
553        editor_wrap_guide: this
554            .editor_wrap_guide
555            .as_ref()
556            .and_then(|color| try_parse_color(color).ok()),
557        editor_active_wrap_guide: this
558            .editor_active_wrap_guide
559            .as_ref()
560            .and_then(|color| try_parse_color(color).ok()),
561        editor_indent_guide: this
562            .editor_indent_guide
563            .as_ref()
564            .and_then(|color| try_parse_color(color).ok()),
565        editor_indent_guide_active: this
566            .editor_indent_guide_active
567            .as_ref()
568            .and_then(|color| try_parse_color(color).ok()),
569        editor_document_highlight_read_background,
570        editor_document_highlight_write_background: this
571            .editor_document_highlight_write_background
572            .as_ref()
573            .and_then(|color| try_parse_color(color).ok()),
574        editor_document_highlight_bracket_background: this
575            .editor_document_highlight_bracket_background
576            .as_ref()
577            .and_then(|color| try_parse_color(color).ok())
578            .or(editor_document_highlight_read_background),
579        terminal_background: this
580            .terminal_background
581            .as_ref()
582            .and_then(|color| try_parse_color(color).ok()),
583        terminal_ansi_background: this
584            .terminal_ansi_background
585            .as_ref()
586            .and_then(|color| try_parse_color(color).ok()),
587        terminal_foreground: this
588            .terminal_foreground
589            .as_ref()
590            .and_then(|color| try_parse_color(color).ok()),
591        terminal_bright_foreground: this
592            .terminal_bright_foreground
593            .as_ref()
594            .and_then(|color| try_parse_color(color).ok()),
595        terminal_dim_foreground: this
596            .terminal_dim_foreground
597            .as_ref()
598            .and_then(|color| try_parse_color(color).ok()),
599        terminal_ansi_black: this
600            .terminal_ansi_black
601            .as_ref()
602            .and_then(|color| try_parse_color(color).ok()),
603        terminal_ansi_bright_black: this
604            .terminal_ansi_bright_black
605            .as_ref()
606            .and_then(|color| try_parse_color(color).ok()),
607        terminal_ansi_dim_black: this
608            .terminal_ansi_dim_black
609            .as_ref()
610            .and_then(|color| try_parse_color(color).ok()),
611        terminal_ansi_red: this
612            .terminal_ansi_red
613            .as_ref()
614            .and_then(|color| try_parse_color(color).ok()),
615        terminal_ansi_bright_red: this
616            .terminal_ansi_bright_red
617            .as_ref()
618            .and_then(|color| try_parse_color(color).ok()),
619        terminal_ansi_dim_red: this
620            .terminal_ansi_dim_red
621            .as_ref()
622            .and_then(|color| try_parse_color(color).ok()),
623        terminal_ansi_green: this
624            .terminal_ansi_green
625            .as_ref()
626            .and_then(|color| try_parse_color(color).ok()),
627        terminal_ansi_bright_green: this
628            .terminal_ansi_bright_green
629            .as_ref()
630            .and_then(|color| try_parse_color(color).ok()),
631        terminal_ansi_dim_green: this
632            .terminal_ansi_dim_green
633            .as_ref()
634            .and_then(|color| try_parse_color(color).ok()),
635        terminal_ansi_yellow: this
636            .terminal_ansi_yellow
637            .as_ref()
638            .and_then(|color| try_parse_color(color).ok()),
639        terminal_ansi_bright_yellow: this
640            .terminal_ansi_bright_yellow
641            .as_ref()
642            .and_then(|color| try_parse_color(color).ok()),
643        terminal_ansi_dim_yellow: this
644            .terminal_ansi_dim_yellow
645            .as_ref()
646            .and_then(|color| try_parse_color(color).ok()),
647        terminal_ansi_blue: this
648            .terminal_ansi_blue
649            .as_ref()
650            .and_then(|color| try_parse_color(color).ok()),
651        terminal_ansi_bright_blue: this
652            .terminal_ansi_bright_blue
653            .as_ref()
654            .and_then(|color| try_parse_color(color).ok()),
655        terminal_ansi_dim_blue: this
656            .terminal_ansi_dim_blue
657            .as_ref()
658            .and_then(|color| try_parse_color(color).ok()),
659        terminal_ansi_magenta: this
660            .terminal_ansi_magenta
661            .as_ref()
662            .and_then(|color| try_parse_color(color).ok()),
663        terminal_ansi_bright_magenta: this
664            .terminal_ansi_bright_magenta
665            .as_ref()
666            .and_then(|color| try_parse_color(color).ok()),
667        terminal_ansi_dim_magenta: this
668            .terminal_ansi_dim_magenta
669            .as_ref()
670            .and_then(|color| try_parse_color(color).ok()),
671        terminal_ansi_cyan: this
672            .terminal_ansi_cyan
673            .as_ref()
674            .and_then(|color| try_parse_color(color).ok()),
675        terminal_ansi_bright_cyan: this
676            .terminal_ansi_bright_cyan
677            .as_ref()
678            .and_then(|color| try_parse_color(color).ok()),
679        terminal_ansi_dim_cyan: this
680            .terminal_ansi_dim_cyan
681            .as_ref()
682            .and_then(|color| try_parse_color(color).ok()),
683        terminal_ansi_white: this
684            .terminal_ansi_white
685            .as_ref()
686            .and_then(|color| try_parse_color(color).ok()),
687        terminal_ansi_bright_white: this
688            .terminal_ansi_bright_white
689            .as_ref()
690            .and_then(|color| try_parse_color(color).ok()),
691        terminal_ansi_dim_white: this
692            .terminal_ansi_dim_white
693            .as_ref()
694            .and_then(|color| try_parse_color(color).ok()),
695        link_text_hover: this
696            .link_text_hover
697            .as_ref()
698            .and_then(|color| try_parse_color(color).ok()),
699        version_control_added: this
700            .version_control_added
701            .as_ref()
702            .and_then(|color| try_parse_color(color).ok())
703            .or(status_colors.created),
704        version_control_deleted: this
705            .version_control_deleted
706            .as_ref()
707            .and_then(|color| try_parse_color(color).ok())
708            .or(status_colors.deleted),
709        version_control_modified: this
710            .version_control_modified
711            .as_ref()
712            .and_then(|color| try_parse_color(color).ok())
713            .or(status_colors.modified),
714        version_control_renamed: this
715            .version_control_renamed
716            .as_ref()
717            .and_then(|color| try_parse_color(color).ok())
718            .or(status_colors.modified),
719        version_control_conflict: this
720            .version_control_conflict
721            .as_ref()
722            .and_then(|color| try_parse_color(color).ok())
723            .or(status_colors.ignored),
724        version_control_ignored: this
725            .version_control_ignored
726            .as_ref()
727            .and_then(|color| try_parse_color(color).ok())
728            .or(status_colors.ignored),
729        version_control_word_added: this
730            .version_control_word_added
731            .as_ref()
732            .and_then(|color| try_parse_color(color).ok()),
733        version_control_word_deleted: this
734            .version_control_word_deleted
735            .as_ref()
736            .and_then(|color| try_parse_color(color).ok()),
737        #[allow(deprecated)]
738        version_control_conflict_marker_ours: this
739            .version_control_conflict_marker_ours
740            .as_ref()
741            .or(this.version_control_conflict_ours_background.as_ref())
742            .and_then(|color| try_parse_color(color).ok()),
743        #[allow(deprecated)]
744        version_control_conflict_marker_theirs: this
745            .version_control_conflict_marker_theirs
746            .as_ref()
747            .or(this.version_control_conflict_theirs_background.as_ref())
748            .and_then(|color| try_parse_color(color).ok()),
749        vim_normal_background: this
750            .vim_normal_background
751            .as_ref()
752            .and_then(|color| try_parse_color(color).ok()),
753        vim_insert_background: this
754            .vim_insert_background
755            .as_ref()
756            .and_then(|color| try_parse_color(color).ok()),
757        vim_replace_background: this
758            .vim_replace_background
759            .as_ref()
760            .and_then(|color| try_parse_color(color).ok()),
761        vim_visual_background: this
762            .vim_visual_background
763            .as_ref()
764            .and_then(|color| try_parse_color(color).ok()),
765        vim_visual_line_background: this
766            .vim_visual_line_background
767            .as_ref()
768            .and_then(|color| try_parse_color(color).ok()),
769        vim_visual_block_background: this
770            .vim_visual_block_background
771            .as_ref()
772            .and_then(|color| try_parse_color(color).ok()),
773        vim_yank_background: this
774            .vim_yank_background
775            .as_ref()
776            .and_then(|color| try_parse_color(color).ok())
777            .or(editor_document_highlight_read_background),
778        vim_helix_normal_background: this
779            .vim_helix_normal_background
780            .as_ref()
781            .and_then(|color| try_parse_color(color).ok()),
782        vim_helix_select_background: this
783            .vim_helix_select_background
784            .as_ref()
785            .and_then(|color| try_parse_color(color).ok()),
786        vim_normal_foreground: this
787            .vim_normal_foreground
788            .as_ref()
789            .and_then(|color| try_parse_color(color).ok()),
790        vim_insert_foreground: this
791            .vim_insert_foreground
792            .as_ref()
793            .and_then(|color| try_parse_color(color).ok()),
794        vim_replace_foreground: this
795            .vim_replace_foreground
796            .as_ref()
797            .and_then(|color| try_parse_color(color).ok()),
798        vim_visual_foreground: this
799            .vim_visual_foreground
800            .as_ref()
801            .and_then(|color| try_parse_color(color).ok()),
802        vim_visual_line_foreground: this
803            .vim_visual_line_foreground
804            .as_ref()
805            .and_then(|color| try_parse_color(color).ok()),
806        vim_visual_block_foreground: this
807            .vim_visual_block_foreground
808            .as_ref()
809            .and_then(|color| try_parse_color(color).ok()),
810        vim_helix_normal_foreground: this
811            .vim_helix_normal_foreground
812            .as_ref()
813            .and_then(|color| try_parse_color(color).ok()),
814        vim_helix_select_foreground: this
815            .vim_helix_select_foreground
816            .as_ref()
817            .and_then(|color| try_parse_color(color).ok()),
818    }
819}
820
821fn ensure_non_opaque(color: Hsla) -> Hsla {
822    const MAXIMUM_OPACITY: f32 = 0.7;
823    if color.a <= MAXIMUM_OPACITY {
824        color
825    } else {
826        Hsla {
827            a: MAXIMUM_OPACITY,
828            ..color
829        }
830    }
831}
832
833fn ensure_opaque(color: Hsla) -> Hsla {
834    Hsla { a: 1.0, ..color }
835}
836
837fn try_parse_color(color: &str) -> anyhow::Result<Hsla> {
838    let rgba = gpui::Rgba::try_from(color)?;
839    let rgba = palette::rgb::Srgba::from_components((rgba.r, rgba.g, rgba.b, rgba.a));
840    let hsla = palette::Hsla::from_color(rgba);
841
842    let hsla = gpui::hsla(
843        hsla.hue.into_positive_degrees() / 360.,
844        hsla.saturation,
845        hsla.lightness,
846        hsla.alpha,
847    );
848
849    Ok(hsla)
850}