1use gpui::{HighlightStyle, Hsla};
2
3#[derive(Clone, Default)]
4pub struct SyntaxTheme {
5 pub highlights: Vec<(String, HighlightStyle)>,
6 pub inlay_style: HighlightStyle,
7 pub suggestion_style: HighlightStyle,
8}
9
10impl SyntaxTheme {
11 // TOOD: Get this working with `#[cfg(test)]`. Why isn't it?
12 pub fn new_test(colors: impl IntoIterator<Item = (&'static str, Hsla)>) -> Self {
13 SyntaxTheme {
14 highlights: colors
15 .into_iter()
16 .map(|(key, color)| {
17 (
18 key.to_owned(),
19 HighlightStyle {
20 color: Some(color),
21 ..Default::default()
22 },
23 )
24 })
25 .collect(),
26 inlay_style: HighlightStyle::default(),
27 suggestion_style: HighlightStyle::default(),
28 }
29 }
30
31 pub fn get(&self, name: &str) -> HighlightStyle {
32 self.highlights
33 .iter()
34 .find_map(|entry| if entry.0 == name { Some(entry.1) } else { None })
35 .unwrap_or_default()
36 }
37
38 pub fn color(&self, name: &str) -> Hsla {
39 self.get(name).color.unwrap_or_default()
40 }
41}