use gpui::{HighlightStyle, Hsla}; #[derive(Clone, Default)] pub struct SyntaxTheme { pub highlights: Vec<(String, HighlightStyle)>, } impl SyntaxTheme { // TOOD: Get this working with `#[cfg(test)]`. Why isn't it? pub fn new_test(colors: impl IntoIterator) -> Self { SyntaxTheme { highlights: colors .into_iter() .map(|(key, color)| { ( key.to_owned(), HighlightStyle { color: Some(color), ..Default::default() }, ) }) .collect(), } } pub fn get(&self, name: &str) -> HighlightStyle { self.highlights .iter() .find_map(|entry| if entry.0 == name { Some(entry.1) } else { None }) .unwrap_or_default() } pub fn color(&self, name: &str) -> Hsla { self.get(name).color.unwrap_or_default() } }