chore: audit components

This commit is contained in:
2026-11-10 15:06:16 +07:00
parent af2177c6c8
commit 03369f501e
92 changed files with 2744 additions and 1947 deletions
+31 -14
View File
@@ -2,22 +2,39 @@
use crate::definition::ThemeDefinition;
const TOKYO_NIGHT: &str = include_str!("../presets/tokyo-night.toml");
/// The bundled presets: `(name, TOML source)`. Enumeration and lookup both
/// read this one table.
const PRESETS: &[(&str, &str)] = &[("tokyo-night", include_str!("../presets/tokyo-night.toml"))];
pub fn preset_names() -> &'static [&'static str] {
&["tokyo-night"]
/// Every bundled preset's name.
pub fn preset_names() -> impl Iterator<Item = &'static str> {
PRESETS.iter().map(|(name, _)| *name)
}
/// Parses the named preset.
pub fn builtin(name: &str) -> Option<ThemeDefinition> {
match name {
"tokyo-night" => match ThemeDefinition::parse_toml(TOKYO_NIGHT) {
Ok(def) => Some(def),
Err(err) => {
eprintln!("bundled preset tokyo-night failed to parse: {err}");
None
}
},
_ => None,
/// Parses the named preset, returning its static name and definition.
pub fn builtin(name: &str) -> Option<(&'static str, ThemeDefinition)> {
let (name, source) = PRESETS
.iter()
.find(|(candidate, _)| *candidate == name)
.copied()?;
match ThemeDefinition::parse_toml(source) {
Ok(definition) => Some((name, definition)),
Err(error) => {
log::error!("bundled preset {name} failed to parse: {error}");
None
}
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn the_name_table_and_lookup_agree() {
for name in preset_names() {
assert!(builtin(name).is_some(), "{name} fails to parse");
}
assert!(builtin("no-such-preset").is_none());
}
}