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