feat(doc): added custom theeming description and advanced error parsing

This commit is contained in:
objz committed 2026-08-15 21:03:45 +02:00
1 parent 4ad7cfb757
commit 6155236a4c
5 files changed
+103 -7

No files matched your search

+38 -1
View File
@@ -163,7 +163,44 @@ rmcl ships with 10 built-in themes:
`catppuccin` · `dracula` · `nord` · `gruvbox` · `one-dark` · `solarized` · `tailwind` · `tokyo-night` · `rose-pine` · `terminal`
you can create your own by dropping a TOML file in `~/.config/rmcl/theme/` and referencing it by name, or point to an absolute path.
pick one in `~/.config/rmcl/theme.toml`:
```toml
theme = "gruvbox"
border_style = "rounded" # rounded | plain | double | thick
```
### custom themes
drop a TOML file in `~/.config/rmcl/theme/` and reference it by name, or point `theme` at an absolute path. keys are flat and top level, don't nest them under `[theme]`. only `name`, `id` and `accent` are required, the rest falls back to a default:
```toml
# ~/.config/rmcl/theme/my-theme.toml
name = "My Theme"
id = "my-theme"
accent = { Rgb = [249, 115, 22] }
accent_dim = "#7f5539"
text = "#cdd6f4"
text_dim = "DarkGray"
text_bright = "#ffffff"
success = "#a6e3a1"
error = "#f38ba8"
warning = "#f9e2af"
info = "#89dceb"
diff_added = "#a6e3a1"
diff_removed = "#f38ba8"
diff_context = "DarkGray"
border = "#585b70"
surface = "#313244"
background = "#1e1e2e"
```
then set `theme = "my-theme"` in `theme.toml`.
colors accept `"#f97316"`, ANSI names (`"Red"`, `"LightBlue"`), `{ Rgb = [r, g, b] }` or `{ Indexed = n }`.
note that `[custom]` in `theme.toml` is only for overriding single values of a builtin, it doesn't define a new theme. same for `border_style`, that one lives in `theme.toml`, not in a theme file.
---
+32
View File
@@ -0,0 +1,32 @@
# example custom theme -> ~/.config/rmcl/theme/my-theme.toml
# activate it in ~/.config/rmcl/theme.toml with: theme = "my-theme"
#
# this file is a theme, not the config: keys live at the top level, NOT under
# [theme] or [custom]. only name, id and accent are required; every other key
# falls back to a sane default.
#
# color formats: "#f97316" | "Red" / "LightBlue" (ANSI names) |
# { Rgb = [249, 115, 22] } | { Indexed = 42 }
name = "My Theme"
id = "my-theme"
accent = { Rgb = [249, 115, 22] }
accent_dim = "#7f5539"
text = "#cdd6f4"
text_dim = "DarkGray"
text_bright = "#ffffff"
success = "#a6e3a1"
error = "#f38ba8"
warning = "#f9e2af"
info = "#89dceb"
diff_added = "#a6e3a1"
diff_removed = "#f38ba8"
diff_context = "DarkGray"
border = "#585b70"
surface = "#313244"
background = "#1e1e2e"
+4 -2
View File
@@ -2,9 +2,11 @@
# catppuccin, dracula, nord, gruvbox, one-dark,
# solarized, tailwind, tokyo-night, rose-pine, terminal
#
# custom themes:
# theme = "my-theme" (loads ~/.config/mcl/theme/my-theme.toml)
# custom themes:
# theme = "my-theme" (loads ~/.config/rmcl/theme/my-theme.toml)
# theme = "/path/to/file" (loads from absolute path)
# a theme file has flat top-level keys (name, id, accent, ...), not the
# [custom] table below. see assets/example-theme.toml in the repo.
theme = "gruvbox"
# rounded, plain, double, thick
+22
View File
@@ -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
View File
@@ -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()
),
}
}