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
23fn 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 let search_match_background = this
291 .search_match_background
292 .as_ref()
293 .and_then(|color| try_parse_color(color).ok());
294 let search_active_match_background = this
295 .search_active_match_background
296 .as_ref()
297 .and_then(|color| try_parse_color(color).ok())
298 .or(search_match_background);
299 ThemeColorsRefinement {
300 border,
301 border_variant: this
302 .border_variant
303 .as_ref()
304 .and_then(|color| try_parse_color(color).ok()),
305 border_focused: this
306 .border_focused
307 .as_ref()
308 .and_then(|color| try_parse_color(color).ok()),
309 border_selected: this
310 .border_selected
311 .as_ref()
312 .and_then(|color| try_parse_color(color).ok()),
313 border_transparent: this
314 .border_transparent
315 .as_ref()
316 .and_then(|color| try_parse_color(color).ok()),
317 border_disabled: this
318 .border_disabled
319 .as_ref()
320 .and_then(|color| try_parse_color(color).ok()),
321 elevated_surface_background: this
322 .elevated_surface_background
323 .as_ref()
324 .and_then(|color| try_parse_color(color).ok()),
325 surface_background: this
326 .surface_background
327 .as_ref()
328 .and_then(|color| try_parse_color(color).ok()),
329 background: this
330 .background
331 .as_ref()
332 .and_then(|color| try_parse_color(color).ok()),
333 element_background: this
334 .element_background
335 .as_ref()
336 .and_then(|color| try_parse_color(color).ok()),
337 element_hover,
338 element_active: this
339 .element_active
340 .as_ref()
341 .and_then(|color| try_parse_color(color).ok()),
342 element_selected: this
343 .element_selected
344 .as_ref()
345 .and_then(|color| try_parse_color(color).ok()),
346 element_disabled: this
347 .element_disabled
348 .as_ref()
349 .and_then(|color| try_parse_color(color).ok()),
350 element_selection_background: this
351 .element_selection_background
352 .as_ref()
353 .and_then(|color| try_parse_color(color).ok()),
354 drop_target_background: this
355 .drop_target_background
356 .as_ref()
357 .and_then(|color| try_parse_color(color).ok()),
358 drop_target_border: this
359 .drop_target_border
360 .as_ref()
361 .and_then(|color| try_parse_color(color).ok()),
362 ghost_element_background: this
363 .ghost_element_background
364 .as_ref()
365 .and_then(|color| try_parse_color(color).ok()),
366 ghost_element_hover: this
367 .ghost_element_hover
368 .as_ref()
369 .and_then(|color| try_parse_color(color).ok()),
370 ghost_element_active: this
371 .ghost_element_active
372 .as_ref()
373 .and_then(|color| try_parse_color(color).ok()),
374 ghost_element_selected: this
375 .ghost_element_selected
376 .as_ref()
377 .and_then(|color| try_parse_color(color).ok()),
378 ghost_element_disabled: this
379 .ghost_element_disabled
380 .as_ref()
381 .and_then(|color| try_parse_color(color).ok()),
382 text: this
383 .text
384 .as_ref()
385 .and_then(|color| try_parse_color(color).ok()),
386 text_muted: this
387 .text_muted
388 .as_ref()
389 .and_then(|color| try_parse_color(color).ok()),
390 text_placeholder: this
391 .text_placeholder
392 .as_ref()
393 .and_then(|color| try_parse_color(color).ok()),
394 text_disabled: this
395 .text_disabled
396 .as_ref()
397 .and_then(|color| try_parse_color(color).ok()),
398 text_accent: this
399 .text_accent
400 .as_ref()
401 .and_then(|color| try_parse_color(color).ok()),
402 icon: this
403 .icon
404 .as_ref()
405 .and_then(|color| try_parse_color(color).ok()),
406 icon_muted: this
407 .icon_muted
408 .as_ref()
409 .and_then(|color| try_parse_color(color).ok()),
410 icon_disabled: this
411 .icon_disabled
412 .as_ref()
413 .and_then(|color| try_parse_color(color).ok()),
414 icon_placeholder: this
415 .icon_placeholder
416 .as_ref()
417 .and_then(|color| try_parse_color(color).ok()),
418 icon_accent: this
419 .icon_accent
420 .as_ref()
421 .and_then(|color| try_parse_color(color).ok()),
422 debugger_accent: this
423 .debugger_accent
424 .as_ref()
425 .and_then(|color| try_parse_color(color).ok()),
426 status_bar_background: this
427 .status_bar_background
428 .as_ref()
429 .and_then(|color| try_parse_color(color).ok()),
430 title_bar_background: this
431 .title_bar_background
432 .as_ref()
433 .and_then(|color| try_parse_color(color).ok()),
434 title_bar_inactive_background: this
435 .title_bar_inactive_background
436 .as_ref()
437 .and_then(|color| try_parse_color(color).ok()),
438 toolbar_background: this
439 .toolbar_background
440 .as_ref()
441 .and_then(|color| try_parse_color(color).ok()),
442 tab_bar_background: this
443 .tab_bar_background
444 .as_ref()
445 .and_then(|color| try_parse_color(color).ok()),
446 tab_inactive_background: this
447 .tab_inactive_background
448 .as_ref()
449 .and_then(|color| try_parse_color(color).ok()),
450 tab_active_background: this
451 .tab_active_background
452 .as_ref()
453 .and_then(|color| try_parse_color(color).ok()),
454 search_match_background: search_match_background,
455 search_active_match_background: search_active_match_background,
456 panel_background,
457 panel_focused_border: this
458 .panel_focused_border
459 .as_ref()
460 .and_then(|color| try_parse_color(color).ok()),
461 panel_indent_guide: this
462 .panel_indent_guide
463 .as_ref()
464 .and_then(|color| try_parse_color(color).ok()),
465 panel_indent_guide_hover: this
466 .panel_indent_guide_hover
467 .as_ref()
468 .and_then(|color| try_parse_color(color).ok()),
469 panel_indent_guide_active: this
470 .panel_indent_guide_active
471 .as_ref()
472 .and_then(|color| try_parse_color(color).ok()),
473 panel_overlay_background: this
474 .panel_overlay_background
475 .as_ref()
476 .and_then(|color| try_parse_color(color).ok())
477 .or(panel_background.map(ensure_opaque)),
478 panel_overlay_hover: this
479 .panel_overlay_hover
480 .as_ref()
481 .and_then(|color| try_parse_color(color).ok())
482 .or(panel_background
483 .zip(element_hover)
484 .map(|(panel_bg, hover_bg)| panel_bg.blend(hover_bg))
485 .map(ensure_opaque)),
486 pane_focused_border: this
487 .pane_focused_border
488 .as_ref()
489 .and_then(|color| try_parse_color(color).ok()),
490 pane_group_border: this
491 .pane_group_border
492 .as_ref()
493 .and_then(|color| try_parse_color(color).ok())
494 .or(border),
495 scrollbar_thumb_background,
496 scrollbar_thumb_hover_background,
497 scrollbar_thumb_active_background,
498 scrollbar_thumb_border,
499 scrollbar_track_background: this
500 .scrollbar_track_background
501 .as_ref()
502 .and_then(|color| try_parse_color(color).ok()),
503 scrollbar_track_border: this
504 .scrollbar_track_border
505 .as_ref()
506 .and_then(|color| try_parse_color(color).ok()),
507 minimap_thumb_background: this
508 .minimap_thumb_background
509 .as_ref()
510 .and_then(|color| try_parse_color(color).ok())
511 .or(scrollbar_thumb_background.map(ensure_non_opaque)),
512 minimap_thumb_hover_background: this
513 .minimap_thumb_hover_background
514 .as_ref()
515 .and_then(|color| try_parse_color(color).ok())
516 .or(scrollbar_thumb_hover_background.map(ensure_non_opaque)),
517 minimap_thumb_active_background: this
518 .minimap_thumb_active_background
519 .as_ref()
520 .and_then(|color| try_parse_color(color).ok())
521 .or(scrollbar_thumb_active_background.map(ensure_non_opaque)),
522 minimap_thumb_border: this
523 .minimap_thumb_border
524 .as_ref()
525 .and_then(|color| try_parse_color(color).ok())
526 .or(scrollbar_thumb_border),
527 editor_foreground: this
528 .editor_foreground
529 .as_ref()
530 .and_then(|color| try_parse_color(color).ok()),
531 editor_background: this
532 .editor_background
533 .as_ref()
534 .and_then(|color| try_parse_color(color).ok()),
535 editor_gutter_background: this
536 .editor_gutter_background
537 .as_ref()
538 .and_then(|color| try_parse_color(color).ok()),
539 editor_subheader_background: this
540 .editor_subheader_background
541 .as_ref()
542 .and_then(|color| try_parse_color(color).ok()),
543 editor_active_line_background: this
544 .editor_active_line_background
545 .as_ref()
546 .and_then(|color| try_parse_color(color).ok()),
547 editor_highlighted_line_background: this
548 .editor_highlighted_line_background
549 .as_ref()
550 .and_then(|color| try_parse_color(color).ok()),
551 editor_debugger_active_line_background: this
552 .editor_debugger_active_line_background
553 .as_ref()
554 .and_then(|color| try_parse_color(color).ok()),
555 editor_line_number: this
556 .editor_line_number
557 .as_ref()
558 .and_then(|color| try_parse_color(color).ok()),
559 editor_hover_line_number: this
560 .editor_hover_line_number
561 .as_ref()
562 .and_then(|color| try_parse_color(color).ok()),
563 editor_active_line_number: this
564 .editor_active_line_number
565 .as_ref()
566 .and_then(|color| try_parse_color(color).ok()),
567 editor_invisible: this
568 .editor_invisible
569 .as_ref()
570 .and_then(|color| try_parse_color(color).ok()),
571 editor_wrap_guide: this
572 .editor_wrap_guide
573 .as_ref()
574 .and_then(|color| try_parse_color(color).ok()),
575 editor_active_wrap_guide: this
576 .editor_active_wrap_guide
577 .as_ref()
578 .and_then(|color| try_parse_color(color).ok()),
579 editor_indent_guide: this
580 .editor_indent_guide
581 .as_ref()
582 .and_then(|color| try_parse_color(color).ok()),
583 editor_indent_guide_active: this
584 .editor_indent_guide_active
585 .as_ref()
586 .and_then(|color| try_parse_color(color).ok()),
587 editor_document_highlight_read_background,
588 editor_document_highlight_write_background: this
589 .editor_document_highlight_write_background
590 .as_ref()
591 .and_then(|color| try_parse_color(color).ok()),
592 editor_document_highlight_bracket_background: this
593 .editor_document_highlight_bracket_background
594 .as_ref()
595 .and_then(|color| try_parse_color(color).ok())
596 // Fall back to `editor.document_highlight.read_background`, for backwards compatibility.
597 .or(editor_document_highlight_read_background),
598 terminal_background: this
599 .terminal_background
600 .as_ref()
601 .and_then(|color| try_parse_color(color).ok()),
602 terminal_ansi_background: this
603 .terminal_ansi_background
604 .as_ref()
605 .and_then(|color| try_parse_color(color).ok()),
606 terminal_foreground: this
607 .terminal_foreground
608 .as_ref()
609 .and_then(|color| try_parse_color(color).ok()),
610 terminal_bright_foreground: this
611 .terminal_bright_foreground
612 .as_ref()
613 .and_then(|color| try_parse_color(color).ok()),
614 terminal_dim_foreground: this
615 .terminal_dim_foreground
616 .as_ref()
617 .and_then(|color| try_parse_color(color).ok()),
618 terminal_ansi_black: this
619 .terminal_ansi_black
620 .as_ref()
621 .and_then(|color| try_parse_color(color).ok()),
622 terminal_ansi_bright_black: this
623 .terminal_ansi_bright_black
624 .as_ref()
625 .and_then(|color| try_parse_color(color).ok()),
626 terminal_ansi_dim_black: this
627 .terminal_ansi_dim_black
628 .as_ref()
629 .and_then(|color| try_parse_color(color).ok()),
630 terminal_ansi_red: this
631 .terminal_ansi_red
632 .as_ref()
633 .and_then(|color| try_parse_color(color).ok()),
634 terminal_ansi_bright_red: this
635 .terminal_ansi_bright_red
636 .as_ref()
637 .and_then(|color| try_parse_color(color).ok()),
638 terminal_ansi_dim_red: this
639 .terminal_ansi_dim_red
640 .as_ref()
641 .and_then(|color| try_parse_color(color).ok()),
642 terminal_ansi_green: this
643 .terminal_ansi_green
644 .as_ref()
645 .and_then(|color| try_parse_color(color).ok()),
646 terminal_ansi_bright_green: this
647 .terminal_ansi_bright_green
648 .as_ref()
649 .and_then(|color| try_parse_color(color).ok()),
650 terminal_ansi_dim_green: this
651 .terminal_ansi_dim_green
652 .as_ref()
653 .and_then(|color| try_parse_color(color).ok()),
654 terminal_ansi_yellow: this
655 .terminal_ansi_yellow
656 .as_ref()
657 .and_then(|color| try_parse_color(color).ok()),
658 terminal_ansi_bright_yellow: this
659 .terminal_ansi_bright_yellow
660 .as_ref()
661 .and_then(|color| try_parse_color(color).ok()),
662 terminal_ansi_dim_yellow: this
663 .terminal_ansi_dim_yellow
664 .as_ref()
665 .and_then(|color| try_parse_color(color).ok()),
666 terminal_ansi_blue: this
667 .terminal_ansi_blue
668 .as_ref()
669 .and_then(|color| try_parse_color(color).ok()),
670 terminal_ansi_bright_blue: this
671 .terminal_ansi_bright_blue
672 .as_ref()
673 .and_then(|color| try_parse_color(color).ok()),
674 terminal_ansi_dim_blue: this
675 .terminal_ansi_dim_blue
676 .as_ref()
677 .and_then(|color| try_parse_color(color).ok()),
678 terminal_ansi_magenta: this
679 .terminal_ansi_magenta
680 .as_ref()
681 .and_then(|color| try_parse_color(color).ok()),
682 terminal_ansi_bright_magenta: this
683 .terminal_ansi_bright_magenta
684 .as_ref()
685 .and_then(|color| try_parse_color(color).ok()),
686 terminal_ansi_dim_magenta: this
687 .terminal_ansi_dim_magenta
688 .as_ref()
689 .and_then(|color| try_parse_color(color).ok()),
690 terminal_ansi_cyan: this
691 .terminal_ansi_cyan
692 .as_ref()
693 .and_then(|color| try_parse_color(color).ok()),
694 terminal_ansi_bright_cyan: this
695 .terminal_ansi_bright_cyan
696 .as_ref()
697 .and_then(|color| try_parse_color(color).ok()),
698 terminal_ansi_dim_cyan: this
699 .terminal_ansi_dim_cyan
700 .as_ref()
701 .and_then(|color| try_parse_color(color).ok()),
702 terminal_ansi_white: this
703 .terminal_ansi_white
704 .as_ref()
705 .and_then(|color| try_parse_color(color).ok()),
706 terminal_ansi_bright_white: this
707 .terminal_ansi_bright_white
708 .as_ref()
709 .and_then(|color| try_parse_color(color).ok()),
710 terminal_ansi_dim_white: this
711 .terminal_ansi_dim_white
712 .as_ref()
713 .and_then(|color| try_parse_color(color).ok()),
714 link_text_hover: this
715 .link_text_hover
716 .as_ref()
717 .and_then(|color| try_parse_color(color).ok()),
718 version_control_added: this
719 .version_control_added
720 .as_ref()
721 .and_then(|color| try_parse_color(color).ok())
722 // Fall back to `created`, for backwards compatibility.
723 .or(status_colors.created),
724 version_control_deleted: this
725 .version_control_deleted
726 .as_ref()
727 .and_then(|color| try_parse_color(color).ok())
728 // Fall back to `deleted`, for backwards compatibility.
729 .or(status_colors.deleted),
730 version_control_modified: this
731 .version_control_modified
732 .as_ref()
733 .and_then(|color| try_parse_color(color).ok())
734 // Fall back to `modified`, for backwards compatibility.
735 .or(status_colors.modified),
736 version_control_renamed: this
737 .version_control_renamed
738 .as_ref()
739 .and_then(|color| try_parse_color(color).ok())
740 // Fall back to `modified`, for backwards compatibility.
741 .or(status_colors.modified),
742 version_control_conflict: this
743 .version_control_conflict
744 .as_ref()
745 .and_then(|color| try_parse_color(color).ok())
746 // Fall back to `ignored`, for backwards compatibility.
747 .or(status_colors.ignored),
748 version_control_ignored: this
749 .version_control_ignored
750 .as_ref()
751 .and_then(|color| try_parse_color(color).ok())
752 // Fall back to `conflict`, for backwards compatibility.
753 .or(status_colors.ignored),
754 version_control_word_added: this
755 .version_control_word_added
756 .as_ref()
757 .and_then(|color| try_parse_color(color).ok()),
758 version_control_word_deleted: this
759 .version_control_word_deleted
760 .as_ref()
761 .and_then(|color| try_parse_color(color).ok()),
762 #[allow(deprecated)]
763 version_control_conflict_marker_ours: this
764 .version_control_conflict_marker_ours
765 .as_ref()
766 .or(this.version_control_conflict_ours_background.as_ref())
767 .and_then(|color| try_parse_color(color).ok()),
768 #[allow(deprecated)]
769 version_control_conflict_marker_theirs: this
770 .version_control_conflict_marker_theirs
771 .as_ref()
772 .or(this.version_control_conflict_theirs_background.as_ref())
773 .and_then(|color| try_parse_color(color).ok()),
774 vim_normal_background: this
775 .vim_normal_background
776 .as_ref()
777 .and_then(|color| try_parse_color(color).ok()),
778 vim_insert_background: this
779 .vim_insert_background
780 .as_ref()
781 .and_then(|color| try_parse_color(color).ok()),
782 vim_replace_background: this
783 .vim_replace_background
784 .as_ref()
785 .and_then(|color| try_parse_color(color).ok()),
786 vim_visual_background: this
787 .vim_visual_background
788 .as_ref()
789 .and_then(|color| try_parse_color(color).ok()),
790 vim_visual_line_background: this
791 .vim_visual_line_background
792 .as_ref()
793 .and_then(|color| try_parse_color(color).ok()),
794 vim_visual_block_background: this
795 .vim_visual_block_background
796 .as_ref()
797 .and_then(|color| try_parse_color(color).ok()),
798 vim_helix_normal_background: this
799 .vim_helix_normal_background
800 .as_ref()
801 .and_then(|color| try_parse_color(color).ok()),
802 vim_helix_select_background: this
803 .vim_helix_select_background
804 .as_ref()
805 .and_then(|color| try_parse_color(color).ok()),
806 vim_mode_text: this
807 .vim_mode_text
808 .as_ref()
809 .and_then(|color| try_parse_color(color).ok()),
810 }
811}
812
813pub(crate) fn try_parse_color(color: &str) -> anyhow::Result<Hsla> {
814 let rgba = gpui::Rgba::try_from(color)?;
815 let rgba = palette::rgb::Srgba::from_components((rgba.r, rgba.g, rgba.b, rgba.a));
816 let hsla = palette::Hsla::from_color(rgba);
817
818 let hsla = gpui::hsla(
819 hsla.hue.into_positive_degrees() / 360.,
820 hsla.saturation,
821 hsla.lightness,
822 hsla.alpha,
823 );
824
825 Ok(hsla)
826}