diff --git a/README.md b/README.md index bcf74be..686bb5f 100644 --- a/README.md +++ b/README.md @@ -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. --- diff --git a/assets/example-theme.toml b/assets/example-theme.toml new file mode 100644 index 0000000..e4aa967 --- /dev/null +++ b/assets/example-theme.toml @@ -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" diff --git a/assets/theme.toml b/assets/theme.toml index 39c0699..6d9f45e 100644 --- a/assets/theme.toml +++ b/assets/theme.toml @@ -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 diff --git a/src/config/tests/theme.rs b/src/config/tests/theme.rs index 0acce86..97e3a26 100644 --- a/src/config/tests/theme.rs +++ b/src/config/tests/theme.rs @@ -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::(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::("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::("[theme]\nname = \"X\"\nid = \"x\"\naccent = \"Red\"\n") + .is_err() + ); + assert!(toml::from_str::("accent = \"Red\"\n").is_err()); +} + #[test] fn theme_config_empty_toml_uses_defaults() { let config: ThemeConfig = toml::from_str("").unwrap(); diff --git a/src/config/theme.rs b/src/config/theme.rs index b6c3e0e..1d8642d 100644 --- a/src/config/theme.rs +++ b/src/config/theme.rs @@ -151,10 +151,13 @@ fn load_base_theme(name: &str) -> Box { if let Some(path) = path && let Ok(content) = std::fs::read_to_string(&path) { - if let Ok(custom) = toml::from_str::(&content) { - return Box::new(custom); - } else { - tracing::warn!("Failed to parse theme file: {}", path.display()); + match toml::from_str::(&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() + ), } }