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