use crate::config::Theme;
struct Colors([&'static str; 23]);
const PRESETS: &[(&str, Colors)] = &[
(
"Rustimal dark",
Colors([
"#08090b", "#101216", "#1b1f26", "#d5d9e0", "#e6e9ee", "#52b6cc", "#2b4a5a", "#1d2128", "#ef7a7f",
"#a3cf8c", "#e6c27f", "#78a3f2", "#c49ae6", "#5ccbe0", "#c4c9d1", "#5d6573", "#ff9196", "#b9e3a2",
"#f2d49a", "#9bbcff", "#d8b2f5", "#8be0f0", "#eef0f4",
]),
),
(
"Light",
Colors([
"#f5f6f8", "#ffffff", "#d6dae1", "#24292f", "#24292f", "#0a7ea4", "#cfe3f5", "#24292f", "#cf222e",
"#1a7f37", "#9a6700", "#0969da", "#8250df", "#1b7c83", "#6e7781", "#57606a", "#a40e26", "#2da44e",
"#bf8700", "#218bff", "#a475f9", "#3192aa", "#8c959f",
]),
),
(
"Solarized dark",
Colors([
"#002b36", "#073642", "#0f4a58", "#93a1a1", "#93a1a1", "#268bd2", "#0f4a58", "#073642", "#dc322f",
"#859900", "#b58900", "#268bd2", "#d33682", "#2aa198", "#eee8d5", "#002b36", "#cb4b16", "#586e75",
"#657b83", "#839496", "#6c71c4", "#93a1a1", "#fdf6e3",
]),
),
(
"Nord",
Colors([
"#2e3440", "#3b4252", "#434c5e", "#d8dee9", "#d8dee9", "#88c0d0", "#434c5e", "#3b4252", "#bf616a",
"#a3be8c", "#ebcb8b", "#81a1c1", "#b48ead", "#88c0d0", "#e5e9f0", "#4c566a", "#bf616a", "#a3be8c",
"#ebcb8b", "#81a1c1", "#b48ead", "#8fbcbb", "#eceff4",
]),
),
(
"Dracula",
Colors([
"#282a36", "#313442", "#44475a", "#f8f8f2", "#f8f8f2", "#bd93f9", "#44475a", "#21222c", "#ff5555",
"#50fa7b", "#f1fa8c", "#bd93f9", "#ff79c6", "#8be9fd", "#f8f8f2", "#6272a4", "#ff6e6e", "#69ff94",
"#ffffa5", "#d6acff", "#ff92df", "#a4ffff", "#ffffff",
]),
),
(
"Gruvbox dark",
Colors([
"#282828", "#32302f", "#3c3836", "#ebdbb2", "#ebdbb2", "#fabd2f", "#504945", "#282828", "#cc241d",
"#98971a", "#d79921", "#458588", "#b16286", "#689d6a", "#a89984", "#928374", "#fb4934", "#b8bb26",
"#fabd2f", "#83a598", "#d3869b", "#8ec07c", "#ebdbb2",
]),
),
];
pub fn names() -> Vec<&'static str> {
PRESETS.iter().map(|(name, _)| *name).collect()
}
pub fn preset(index: usize) -> Option<Theme> {
let (_, c) = PRESETS.get(index)?;
let c = &c.0;
let s = |i: usize| c[i].to_string();
Some(Theme {
background: s(0),
surface: s(1),
border: s(2),
foreground: s(3),
cursor: s(4),
accent: s(5),
selection: s(6),
ansi: std::array::from_fn(|i| s(7 + i)),
})
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn every_preset_is_made_of_valid_colors() {
for (i, name) in names().into_iter().enumerate() {
let t = preset(i).unwrap();
let all = [&t.background, &t.surface, &t.border, &t.foreground, &t.cursor, &t.accent, &t.selection]
.into_iter()
.chain(t.ansi.iter());
for color in all {
assert!(crate::config::parse_hex(color).is_some(), "{name}: {color:?} is not a color");
}
}
assert!(preset(99).is_none());
}
#[test]
fn the_first_preset_is_the_default_theme() {
let d = Theme::default();
let p = preset(0).unwrap();
assert_eq!((p.background, p.accent, p.ansi), (d.background, d.accent, d.ansi));
}
}