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