feat(doc): added custom theeming description and advanced error parsing
This commit is contained in:
1 parent
4ad7cfb757
commit
6155236a4c
5 files changed
+103
-7
No files matched your search
@@ -66,6 +66,28 @@ fn resolve_builtin_theme() {
|
||||
assert_eq!(theme.id(), expected);
|
||||
}
|
||||
|
||||
// a theme file in config/theme/ is a flat CustomTheme: name/id/accent are
|
||||
// required, everything else falls back to themekit defaults.
|
||||
#[test]
|
||||
fn custom_theme_file_parses() {
|
||||
let full = toml::from_str::<CustomTheme>(include_str!("../../../assets/example-theme.toml"))
|
||||
.expect("bundled example theme must parse");
|
||||
assert_eq!(full.id, "my-theme");
|
||||
assert_eq!(full.accent, Color::Rgb(249, 115, 22));
|
||||
assert_eq!(full.text, Color::Rgb(205, 214, 244));
|
||||
|
||||
let minimal =
|
||||
toml::from_str::<CustomTheme>("name = \"X\"\nid = \"x\"\naccent = \"#f97316\"\n").unwrap();
|
||||
assert_eq!(minimal.accent, Color::Rgb(249, 115, 22));
|
||||
|
||||
// the two failure modes users hit: nesting under [theme], or omitting name/id
|
||||
assert!(
|
||||
toml::from_str::<CustomTheme>("[theme]\nname = \"X\"\nid = \"x\"\naccent = \"Red\"\n")
|
||||
.is_err()
|
||||
);
|
||||
assert!(toml::from_str::<CustomTheme>("accent = \"Red\"\n").is_err());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn theme_config_empty_toml_uses_defaults() {
|
||||
let config: ThemeConfig = toml::from_str("").unwrap();
|
||||
|
||||
+7
-4
@@ -151,10 +151,13 @@ fn load_base_theme(name: &str) -> Box<dyn Theme> {
|
||||
if let Some(path) = path
|
||||
&& let Ok(content) = std::fs::read_to_string(&path)
|
||||
{
|
||||
if let Ok(custom) = toml::from_str::<CustomTheme>(&content) {
|
||||
return Box::new(custom);
|
||||
} else {
|
||||
tracing::warn!("Failed to parse theme file: {}", path.display());
|
||||
match toml::from_str::<CustomTheme>(&content) {
|
||||
Ok(custom) => return Box::new(custom),
|
||||
Err(e) => tracing::warn!(
|
||||
"Failed to parse theme file {}: {e}. Theme files need top-level \
|
||||
name, id and accent keys (not nested under [theme]).",
|
||||
path.display()
|
||||
),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user