diff options
| author | Alex <a.neyman17@gmail.com> | 2026-08-22 17:18:56 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2026-08-23 00:18:56 +0300 |
| commit | db6f301f1301d85ca7a4271363760836f53ac0d0 (patch) | |
| tree | 7ac8748407268190f3bea23190fb3cfb07bd4bf2 /src/config | |
| parent | 1d604329b0ded93d18fd6b27f72c7473d1fee20f (diff) | |
feat: add per-mode theme overrides (#2324)
* feat: add per-mode theme overrides
allow [theme.custom.light] and [theme.custom.dark] blocks so custom
overrides can differ per resolved appearance when auto_switch flips.
precedence: theme defaults, then [theme.custom], then the block for
the active mode. configs without the new blocks resolve unchanged.
refs #837
* docs: complete per-mode theme documentation
---------
Co-authored-by: Ogulcan Celik <ogulcancelik@gmail.com>
Diffstat (limited to 'src/config')
| -rw-r--r-- | src/config/theme.rs | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/src/config/theme.rs b/src/config/theme.rs index 8f28390c..cb9e3498 100644 --- a/src/config/theme.rs +++ b/src/config/theme.rs @@ -119,6 +119,35 @@ pub struct CustomThemeColors { pub blue: Option<String>, pub teal: Option<String>, pub peach: Option<String>, + /// Overrides applied when `auto_switch` selects a light appearance. + pub light: Option<ModeThemeColors>, + /// Overrides applied when `auto_switch` selects a dark appearance. + pub dark: Option<ModeThemeColors>, +} + +/// Per-token color overrides for one auto-switch appearance. +#[derive(Debug, Clone, Default, Deserialize)] +#[serde(default)] +pub struct ModeThemeColors { + pub accent: Option<String>, + pub panel_bg: Option<String>, + pub sidebar_bg: Option<String>, + pub active_row_bg: Option<String>, + pub selection_bg: Option<String>, + pub surface0: Option<String>, + pub surface1: Option<String>, + pub surface_dim: Option<String>, + pub overlay0: Option<String>, + pub overlay1: Option<String>, + pub text: Option<String>, + pub subtext0: Option<String>, + pub mauve: Option<String>, + pub green: Option<String>, + pub yellow: Option<String>, + pub red: Option<String>, + pub blue: Option<String>, + pub teal: Option<String>, + pub peach: Option<String>, } /// Parse a color string into a ratatui Color. @@ -284,6 +313,35 @@ red = "rgb(255, 85, 85)" } #[test] + fn theme_custom_mode_overrides_parse() { + let toml = r##" +[theme.custom] +accent = "#010203" + +[theme.custom.light] +accent = "#040506" +text = "#070809" +selection_bg = "#101112" + +[theme.custom.dark] +panel_bg = "#0a0b0c" +sidebar_bg = "#0d0e0f" +active_row_bg = "#131415" +"##; + let config: Config = toml::from_str(toml).unwrap(); + let custom = config.theme.custom.as_ref().unwrap(); + assert_eq!(custom.accent.as_deref(), Some("#010203")); + let light = custom.light.as_ref().unwrap(); + assert_eq!(light.accent.as_deref(), Some("#040506")); + assert_eq!(light.text.as_deref(), Some("#070809")); + assert_eq!(light.selection_bg.as_deref(), Some("#101112")); + let dark = custom.dark.as_ref().unwrap(); + assert_eq!(dark.panel_bg.as_deref(), Some("#0a0b0c")); + assert_eq!(dark.sidebar_bg.as_deref(), Some("#0d0e0f")); + assert_eq!(dark.active_row_bg.as_deref(), Some("#131415")); + } + + #[test] fn theme_defaults_when_missing() { let config: Config = toml::from_str("").unwrap(); assert!(config.theme.name.is_none()); |
