use core::ops::ControlFlow;
use crate::{Contrast, Theme, Variant};
use alloc::vec::Vec;
#[allow(unused_variables, unused_mut)]
fn for_each_theme<B>(mut f: impl FnMut(&'static Theme) -> ControlFlow<B>) -> ControlFlow<B> {
#[cfg(feature = "popular")]
for theme in crate::popular::THEMES {
f(theme)?;
}
#[cfg(feature = "base16")]
for theme in crate::base16::THEMES {
f(theme)?;
}
#[cfg(feature = "base24")]
for theme in crate::base24::THEMES {
f(theme)?;
}
#[cfg(feature = "vim")]
for theme in crate::vim::THEMES {
f(theme)?;
}
#[cfg(feature = "emacs")]
for theme in crate::emacs::THEMES {
f(theme)?;
}
ControlFlow::Continue(())
}
pub fn collect_all_themes() -> Vec<&'static Theme> {
let mut themes = Vec::new();
let _ = for_each_theme(|t| -> ControlFlow<()> {
themes.push(t);
ControlFlow::Continue(())
});
themes
}
pub fn find_by_name(name: &str) -> Option<&'static Theme> {
match for_each_theme(|t| {
if t.name == name {
ControlFlow::Break(t)
} else {
ControlFlow::Continue(())
}
}) {
ControlFlow::Break(t) => Some(t),
ControlFlow::Continue(()) => None,
}
}
pub fn filter_by_variant(variant: Variant) -> Vec<&'static Theme> {
let mut out = Vec::new();
let _ = for_each_theme(|t| -> ControlFlow<()> {
if t.variant == variant {
out.push(t);
}
ControlFlow::Continue(())
});
out
}
pub fn filter_by_contrast(contrast: Contrast) -> Vec<&'static Theme> {
let mut out = Vec::new();
let _ = for_each_theme(|t| -> ControlFlow<()> {
if t.contrast == contrast {
out.push(t);
}
ControlFlow::Continue(())
});
out
}