From 15d9d2e8946a235c2c17ebb2048c20658a44cd68 Mon Sep 17 00:00:00 2001 From: Saiyed Shizain Date: Fri, 11 Sep 2026 18:42:23 +0530 Subject: feat: add matugen/noctalia v5 color template support - Add MatugenColors struct reading from ~/.cache/pomoru/colors.json using flat snake_case keys rendered by noctalia v5's template engine - Rename old struct to LegacyNoctaliaColors (kept for backward compat) - Implement priority chain: matugen cache > legacy colors.json > defaults - Fix parse_hex_color to use trim_start_matches instead of fixed-length check, accepting both '#RRGGBB' and 'RRGGBB' formats - Add assets/noctalia/colors-template.json: noctalia template file using {{colors..default.hex}} token syntax - Add assets/noctalia/templates.toml: drop-in user-template config snippet for ~/.config/noctalia/templates.toml --- assets/noctalia/colors-template.json | 6 ++++ assets/noctalia/templates.toml | 28 +++++++++++++++++ src/pomo/state.rs | 60 +++++++++++++++++++++++++++++++----- 3 files changed, 86 insertions(+), 8 deletions(-) create mode 100644 assets/noctalia/colors-template.json create mode 100644 assets/noctalia/templates.toml diff --git a/assets/noctalia/colors-template.json b/assets/noctalia/colors-template.json new file mode 100644 index 0000000..d70e6ff --- /dev/null +++ b/assets/noctalia/colors-template.json @@ -0,0 +1,6 @@ +{ + "primary": "{{colors.primary.default.hex}}", + "on_surface_variant": "{{colors.on_surface_variant.default.hex}}", + "surface_container": "{{colors.surface_container.default.hex}}", + "on_surface": "{{colors.on_surface.default.hex}}" +} diff --git a/assets/noctalia/templates.toml b/assets/noctalia/templates.toml new file mode 100644 index 0000000..51d3f41 --- /dev/null +++ b/assets/noctalia/templates.toml @@ -0,0 +1,28 @@ +# Noctalia v5 user-template for pomoru +# +# This template tells noctalia to render pomoru's theme colors whenever +# the palette changes, so pomoru always matches your wallpaper-derived scheme. +# +# SETUP +# ----- +# Option A – Drop this file into your noctalia config directory: +# +# cp ~/.config/noctalia/templates.toml ~/.config/noctalia/templates.toml.bak # optional backup +# cat assets/noctalia/templates.toml >> ~/.config/noctalia/templates.toml +# +# Option B – Add the block below to ~/.config/noctalia/templates.toml manually. +# +# After adding it, noctalia will render the colors on the next palette change, +# or immediately via: noctalia theme --render-templates + +[theme.templates.user.pomoru] +input_path = "$XDG_CONFIG_HOME/noctalia/templates/pomoru-colors.json" +output_path = "$XDG_CACHE_HOME/pomoru/colors.json" + +# TEMPLATE FILE +# ------------- +# Copy the template to the input_path above: +# +# mkdir -p ~/.config/noctalia/templates +# cp assets/noctalia/colors-template.json \ +# ~/.config/noctalia/templates/pomoru-colors.json diff --git a/src/pomo/state.rs b/src/pomo/state.rs index 83e2038..bf7daef 100644 --- a/src/pomo/state.rs +++ b/src/pomo/state.rs @@ -12,9 +12,21 @@ pub struct Theme { pub text: Color, } +/// Color format rendered by noctalia v5's matugen template system. +/// Pomoru reads this from `~/.cache/pomoru/colors.json` when available. +#[derive(Deserialize)] +struct MatugenColors { + primary: String, + on_surface_variant: String, + surface_container: String, + on_surface: String, +} + +/// Legacy color format from `~/.config/noctalia/colors.json` (noctalia < v5). +/// Kept for backward compatibility. #[derive(Deserialize)] #[serde(rename_all = "camelCase")] -struct NoctaliaColors { +struct LegacyNoctaliaColors { m_primary: String, m_on_surface_variant: String, m_surface_variant: String, @@ -22,10 +34,11 @@ struct NoctaliaColors { } fn parse_hex_color(hex: &str) -> Option { - if hex.len() == 7 && hex.starts_with('#') { - let r = u8::from_str_radix(&hex[1..3], 16).ok()?; - let g = u8::from_str_radix(&hex[3..5], 16).ok()?; - let b = u8::from_str_radix(&hex[5..7], 16).ok()?; + let hex = hex.trim_start_matches('#'); + if hex.len() == 6 { + let r = u8::from_str_radix(&hex[0..2], 16).ok()?; + let g = u8::from_str_radix(&hex[2..4], 16).ok()?; + let b = u8::from_str_radix(&hex[4..6], 16).ok()?; Some(Color::Rgb(r, g, b)) } else { None @@ -34,6 +47,7 @@ fn parse_hex_color(hex: &str) -> Option { impl Default for Theme { fn default() -> Self { + // Catppuccin Mocha defaults — used when no theme file is present. let mut theme = Self { primary: Color::Rgb(180, 190, 254), overlay0: Color::Rgb(108, 112, 134), @@ -42,9 +56,38 @@ impl Default for Theme { }; if let Some(base_dirs) = BaseDirs::new() { - let path = base_dirs.home_dir().join(".config/noctalia/colors.json"); - if let Ok(content) = fs::read_to_string(&path) - && let Ok(colors) = serde_json::from_str::(&content) + // --- Priority 1: matugen / noctalia v5 rendered colors --- + // Noctalia renders `~/.cache/pomoru/colors.json` via a user template. + // See `assets/noctalia/` for the template and setup instructions. + let matugen_path = base_dirs + .home_dir() + .join(".cache/pomoru/colors.json"); + + if let Ok(content) = fs::read_to_string(&matugen_path) + && let Ok(colors) = serde_json::from_str::(&content) + { + if let Some(c) = parse_hex_color(&colors.primary) { + theme.primary = c; + } + if let Some(c) = parse_hex_color(&colors.on_surface_variant) { + theme.overlay0 = c; + } + if let Some(c) = parse_hex_color(&colors.surface_container) { + theme.surface0 = c; + } + if let Some(c) = parse_hex_color(&colors.on_surface) { + theme.text = c; + } + return theme; + } + + // --- Priority 2: legacy noctalia colors.json (noctalia < v5) --- + let legacy_path = base_dirs + .home_dir() + .join(".config/noctalia/colors.json"); + + if let Ok(content) = fs::read_to_string(&legacy_path) + && let Ok(colors) = serde_json::from_str::(&content) { if let Some(c) = parse_hex_color(&colors.m_primary) { theme.primary = c; @@ -60,6 +103,7 @@ impl Default for Theme { } } } + theme } } -- cgit v1.2.3 From b37fff291e4b5ac3577e865807bb25cf1e03d569 Mon Sep 17 00:00:00 2001 From: Saiyed Shizain Date: Fri, 11 Sep 2026 18:42:30 +0530 Subject: docs: update README with theming section and noctalia v5 setup - Add Theming section with priority table (matugen > legacy > defaults) - Document noctalia v5 setup: copy template + append templates.toml entry - Add noctalia theme --render-templates usage tip - Update Design feature bullet to reference noctalia v5 and matugen --- README.md | 44 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 2483d09..d63c7ab 100644 --- a/README.md +++ b/README.md @@ -32,7 +32,7 @@ A minimalist Pomodoro TUI with a task list, written in Rust. - Keyboard-only interaction - Minimalist interface -- Dynamic theming system (for Noctalia Shell users) +- Dynamic theming via [Noctalia](https://noctalia.dev) (v5 matugen templates + legacy `colors.json`) - Configuration saved locally --- @@ -146,6 +146,48 @@ The previously stated `status.json` can be used in Waybar as follows: --- +## Theming + +Pomoru picks up colors in this priority order: + +| Priority | Source | When it applies | +|----------|--------|-----------------| +| 1 | `~/.cache/pomoru/colors.json` | Noctalia v5 matugen template (recommended) | +| 2 | `~/.config/noctalia/colors.json` | Legacy noctalia `< v5` format | +| 3 | Built-in defaults | Catppuccin Mocha palette | + +### Noctalia v5 (matugen) — recommended + +Copy the template and add the user-template entry so noctalia re-renders pomoru's colors whenever your palette changes: + +```bash +# 1. Copy the template file +mkdir -p ~/.config/noctalia/templates +cp assets/noctalia/colors-template.json \ + ~/.config/noctalia/templates/pomoru-colors.json + +# 2. Append the template entry to your noctalia templates config +cat assets/noctalia/templates.toml >> ~/.config/noctalia/templates.toml + +# 3. Trigger an immediate render (or just change your wallpaper) +noctalia theme --render-templates +``` + +The template entry noctalia needs is: + +```toml +[theme.templates.user.pomoru] +input_path = "$XDG_CONFIG_HOME/noctalia/templates/pomoru-colors.json" +output_path = "$XDG_CACHE_HOME/pomoru/colors.json" +``` + +### Legacy noctalia (`< v5`) + +No setup required. If `~/.config/noctalia/colors.json` exists and the +matugen cache file does not, pomoru reads colors from it automatically. + +--- + ## Installation ### Prebuilt binary -- cgit v1.2.3 From 5a90041da51c6813890b05a4bc1f9fcfe67c27de Mon Sep 17 00:00:00 2001 From: Saiyed Shizain Date: Fri, 11 Sep 2026 18:57:51 +0530 Subject: docs: fix noctalia v5 wiring instructions and asset templates.toml - Correct CLI command: noctalia msg templates-apply (not theme --render-templates) - Correct config schema: [theme.templates.user.*] (not matugen's [templates.*]) - Explain {{colors..default.hex}} token syntax in README - Add migration note for v4 users: delete stale colors.json + user-templates.toml - Add noctalia config validate step to setup instructions - Update assets/noctalia/templates.toml with correct setup comments and schema --- README.md | 64 ++++++++++++++++++++++++++++++++++-------- assets/noctalia/templates.toml | 32 ++++++++++----------- 2 files changed, 68 insertions(+), 28 deletions(-) diff --git a/README.md b/README.md index d63c7ab..7f118f8 100644 --- a/README.md +++ b/README.md @@ -152,28 +152,45 @@ Pomoru picks up colors in this priority order: | Priority | Source | When it applies | |----------|--------|-----------------| -| 1 | `~/.cache/pomoru/colors.json` | Noctalia v5 matugen template (recommended) | -| 2 | `~/.config/noctalia/colors.json` | Legacy noctalia `< v5` format | +| 1 | `~/.cache/pomoru/colors.json` | Noctalia v5 user template (recommended) | +| 2 | `~/.config/noctalia/colors.json` | Legacy noctalia v4 format | | 3 | Built-in defaults | Catppuccin Mocha palette | -### Noctalia v5 (matugen) — recommended +### Noctalia v5 — wiring it up -Copy the template and add the user-template entry so noctalia re-renders pomoru's colors whenever your palette changes: +Noctalia v5 uses its own template engine (matugen-compatible `{{colors..default.hex}}` tokens). When the wallpaper or palette changes, noctalia re-renders all configured templates automatically. Pomoru ships the template and config snippet needed to hook into this system. + +**One-time setup:** ```bash -# 1. Copy the template file +# 1. Copy the input template into noctalia's template directory mkdir -p ~/.config/noctalia/templates cp assets/noctalia/colors-template.json \ ~/.config/noctalia/templates/pomoru-colors.json -# 2. Append the template entry to your noctalia templates config +# 2. Register the user template in noctalia's config +# Either append to an existing templates.toml, or create it fresh: cat assets/noctalia/templates.toml >> ~/.config/noctalia/templates.toml -# 3. Trigger an immediate render (or just change your wallpaper) -noctalia theme --render-templates +# 3. Render immediately (no need to change wallpaper) +noctalia msg templates-apply ``` -The template entry noctalia needs is: +After step 3, `~/.cache/pomoru/colors.json` will exist and pomoru picks it +up on the next launch. + +**What noctalia renders** (`assets/noctalia/colors-template.json`): + +```json +{ + "primary": "{{colors.primary.default.hex}}", + "on_surface_variant": "{{colors.on_surface_variant.default.hex}}", + "surface_container": "{{colors.surface_container.default.hex}}", + "on_surface": "{{colors.on_surface.default.hex}}" +} +``` + +**The config block** (`assets/noctalia/templates.toml`) noctalia reads: ```toml [theme.templates.user.pomoru] @@ -181,10 +198,33 @@ input_path = "$XDG_CONFIG_HOME/noctalia/templates/pomoru-colors.json" output_path = "$XDG_CACHE_HOME/pomoru/colors.json" ``` -### Legacy noctalia (`< v5`) +> **Note:** `$XDG_CONFIG_HOME` defaults to `~/.config` and `$XDG_CACHE_HOME` +> defaults to `~/.cache`. Noctalia v5 expands these automatically. + +> **Coming from noctalia v4?** Delete the stale files from `~/.config/noctalia/`: +> - `colors.json` — not read by v5 +> - `user-templates.toml` — uses matugen's old `[templates.*]` schema; v5 will +> warn `templates: unknown section` and ignore it. The v5 schema is +> `[theme.templates.user.*]` in any `*.toml` under `~/.config/noctalia/`. + +**Validate your config:** + +```bash +noctalia config validate ~/.config/noctalia/templates.toml +# → ✓ Config is valid +``` + +**Re-apply without changing wallpaper:** + +```bash +noctalia msg templates-apply +``` + +### Legacy noctalia (v4) -No setup required. If `~/.config/noctalia/colors.json` exists and the -matugen cache file does not, pomoru reads colors from it automatically. +No setup required. If `~/.config/noctalia/colors.json` exists and +`~/.cache/pomoru/colors.json` does not, pomoru reads the legacy camelCase +format automatically. Delete it once you've set up the v5 template above. --- diff --git a/assets/noctalia/templates.toml b/assets/noctalia/templates.toml index 51d3f41..8a48f8c 100644 --- a/assets/noctalia/templates.toml +++ b/assets/noctalia/templates.toml @@ -1,28 +1,28 @@ # Noctalia v5 user-template for pomoru # -# This template tells noctalia to render pomoru's theme colors whenever -# the palette changes, so pomoru always matches your wallpaper-derived scheme. +# This tells noctalia to render pomoru's theme colors whenever the palette +# changes (wallpaper change, manual palette switch, etc.). # # SETUP # ----- -# Option A – Drop this file into your noctalia config directory: +# 1. Copy the input template into noctalia's templates directory: # -# cp ~/.config/noctalia/templates.toml ~/.config/noctalia/templates.toml.bak # optional backup -# cat assets/noctalia/templates.toml >> ~/.config/noctalia/templates.toml +# mkdir -p ~/.config/noctalia/templates +# cp assets/noctalia/colors-template.json \ +# ~/.config/noctalia/templates/pomoru-colors.json # -# Option B – Add the block below to ~/.config/noctalia/templates.toml manually. +# 2. Append this file to your noctalia templates config: # -# After adding it, noctalia will render the colors on the next palette change, -# or immediately via: noctalia theme --render-templates +# cat assets/noctalia/templates.toml >> ~/.config/noctalia/templates.toml +# +# Or create ~/.config/noctalia/templates.toml if it doesn't exist yet. +# +# 3. Apply immediately (noctalia must be running): +# +# noctalia msg templates-apply +# +# Validate: noctalia config validate ~/.config/noctalia/templates.toml [theme.templates.user.pomoru] input_path = "$XDG_CONFIG_HOME/noctalia/templates/pomoru-colors.json" output_path = "$XDG_CACHE_HOME/pomoru/colors.json" - -# TEMPLATE FILE -# ------------- -# Copy the template to the input_path above: -# -# mkdir -p ~/.config/noctalia/templates -# cp assets/noctalia/colors-template.json \ -# ~/.config/noctalia/templates/pomoru-colors.json -- cgit v1.2.3 From 8866dfc0984f1f7f917dfb6b5f0a165f42b446a1 Mon Sep 17 00:00:00 2001 From: Saiyed Shizain Date: Fri, 11 Sep 2026 19:09:45 +0530 Subject: feat: hot-reload theme when colors.json changes --- src/pomo/mod.rs | 19 +++++++++++++ src/pomo/state.rs | 82 +++++++++++++++++++++++++++++++------------------------ 2 files changed, 66 insertions(+), 35 deletions(-) diff --git a/src/pomo/mod.rs b/src/pomo/mod.rs index d1043e8..3a79d40 100644 --- a/src/pomo/mod.rs +++ b/src/pomo/mod.rs @@ -72,6 +72,24 @@ impl Pomo { Ok(()) } + pub fn check_theme_reload(&mut self) { + if let Some(base_dirs) = directories::BaseDirs::new() { + let matugen_path = base_dirs.home_dir().join(".cache/pomoru/colors.json"); + let legacy_path = base_dirs.home_dir().join(".config/noctalia/colors.json"); + + let current_mtime = fs::metadata(&matugen_path) + .or_else(|_| fs::metadata(&legacy_path)) + .and_then(|m| m.modified()) + .ok(); + + if current_mtime != self.theme_mtime { + let (new_theme, new_mtime) = state::Theme::load_with_mtime(); + self.theme = new_theme; + self.theme_mtime = new_mtime; + } + } + } + pub fn save(&self) -> Result<(), Box> { let config = Config { work_time_mins: self.work_time.as_secs() / 60, @@ -127,6 +145,7 @@ impl Pomo { tokio::select! { _ = second_tick.tick() => { self.tick(); + self.check_theme_reload(); let _ = self.export_status(); } diff --git a/src/pomo/state.rs b/src/pomo/state.rs index bf7daef..5be19bb 100644 --- a/src/pomo/state.rs +++ b/src/pomo/state.rs @@ -45,8 +45,8 @@ fn parse_hex_color(hex: &str) -> Option { } } -impl Default for Theme { - fn default() -> Self { +impl Theme { + pub fn load_with_mtime() -> (Self, Option) { // Catppuccin Mocha defaults — used when no theme file is present. let mut theme = Self { primary: Color::Rgb(180, 190, 254), @@ -57,28 +57,28 @@ impl Default for Theme { if let Some(base_dirs) = BaseDirs::new() { // --- Priority 1: matugen / noctalia v5 rendered colors --- - // Noctalia renders `~/.cache/pomoru/colors.json` via a user template. - // See `assets/noctalia/` for the template and setup instructions. let matugen_path = base_dirs .home_dir() .join(".cache/pomoru/colors.json"); - if let Ok(content) = fs::read_to_string(&matugen_path) - && let Ok(colors) = serde_json::from_str::(&content) - { - if let Some(c) = parse_hex_color(&colors.primary) { - theme.primary = c; - } - if let Some(c) = parse_hex_color(&colors.on_surface_variant) { - theme.overlay0 = c; - } - if let Some(c) = parse_hex_color(&colors.surface_container) { - theme.surface0 = c; + if let Ok(metadata) = fs::metadata(&matugen_path) { + if let Ok(content) = fs::read_to_string(&matugen_path) + && let Ok(colors) = serde_json::from_str::(&content) + { + if let Some(c) = parse_hex_color(&colors.primary) { + theme.primary = c; + } + if let Some(c) = parse_hex_color(&colors.on_surface_variant) { + theme.overlay0 = c; + } + if let Some(c) = parse_hex_color(&colors.surface_container) { + theme.surface0 = c; + } + if let Some(c) = parse_hex_color(&colors.on_surface) { + theme.text = c; + } + return (theme, metadata.modified().ok()); } - if let Some(c) = parse_hex_color(&colors.on_surface) { - theme.text = c; - } - return theme; } // --- Priority 2: legacy noctalia colors.json (noctalia < v5) --- @@ -86,25 +86,34 @@ impl Default for Theme { .home_dir() .join(".config/noctalia/colors.json"); - if let Ok(content) = fs::read_to_string(&legacy_path) - && let Ok(colors) = serde_json::from_str::(&content) - { - if let Some(c) = parse_hex_color(&colors.m_primary) { - theme.primary = c; - } - if let Some(c) = parse_hex_color(&colors.m_on_surface_variant) { - theme.overlay0 = c; - } - if let Some(c) = parse_hex_color(&colors.m_surface_variant) { - theme.surface0 = c; - } - if let Some(c) = parse_hex_color(&colors.m_on_surface) { - theme.text = c; + if let Ok(metadata) = fs::metadata(&legacy_path) { + if let Ok(content) = fs::read_to_string(&legacy_path) + && let Ok(colors) = serde_json::from_str::(&content) + { + if let Some(c) = parse_hex_color(&colors.m_primary) { + theme.primary = c; + } + if let Some(c) = parse_hex_color(&colors.m_on_surface_variant) { + theme.overlay0 = c; + } + if let Some(c) = parse_hex_color(&colors.m_surface_variant) { + theme.surface0 = c; + } + if let Some(c) = parse_hex_color(&colors.m_on_surface) { + theme.text = c; + } + return (theme, metadata.modified().ok()); } } } - theme + (theme, None) + } +} + +impl Default for Theme { + fn default() -> Self { + Theme::load_with_mtime().0 } } @@ -174,11 +183,13 @@ pub struct Pomo { pub input_buffer: String, pub should_quit: bool, pub theme: Theme, + pub theme_mtime: Option, } impl Pomo { pub fn new() -> Self { let work = Duration::from_secs(25 * 60); + let (theme, theme_mtime) = Theme::load_with_mtime(); Self { screen: AppScreen::Timer, mode: SessionMode::Work, @@ -195,7 +206,8 @@ impl Pomo { task_state: ListState::default(), input_buffer: String::new(), should_quit: false, - theme: Theme::default(), + theme, + theme_mtime, } } -- cgit v1.2.3 From f0643844857175c3fccec5afb476bab7489d2b2c Mon Sep 17 00:00:00 2001 From: Saiyed Shizain Date: Fri, 11 Sep 2026 19:09:45 +0530 Subject: chore: bump version to 1.2.0 --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 8e375a9..badf644 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "pomoru" -version = "1.1.0" +version = "1.2.0" edition = "2024" [dependencies] -- cgit v1.2.3 From b885efbf21f2839318a46e484654e706821b716e Mon Sep 17 00:00:00 2001 From: Saiyed Shizain Date: Fri, 11 Sep 2026 23:47:11 +0530 Subject: fix: improve hot-reload responsiveness and prevent flashes --- src/pomo/mod.rs | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/pomo/mod.rs b/src/pomo/mod.rs index 3a79d40..2ccecbb 100644 --- a/src/pomo/mod.rs +++ b/src/pomo/mod.rs @@ -82,10 +82,12 @@ impl Pomo { .and_then(|m| m.modified()) .ok(); - if current_mtime != self.theme_mtime { + if current_mtime.is_some() && current_mtime != self.theme_mtime { let (new_theme, new_mtime) = state::Theme::load_with_mtime(); - self.theme = new_theme; - self.theme_mtime = new_mtime; + if new_mtime.is_some() { + self.theme = new_theme; + self.theme_mtime = new_mtime; + } } } } @@ -136,6 +138,7 @@ impl Pomo { let mut terminal = Terminal::new(backend)?; let mut second_tick = tokio::time::interval(Duration::from_secs(1)); + let mut theme_tick = tokio::time::interval(Duration::from_millis(100)); let _ = self.export_status(); @@ -145,10 +148,13 @@ impl Pomo { tokio::select! { _ = second_tick.tick() => { self.tick(); - self.check_theme_reload(); let _ = self.export_status(); } + _ = theme_tick.tick() => { + self.check_theme_reload(); + } + // Tighten poll to 16ms (~60fps feel) for input responsiveness event_res = tokio::task::spawn_blocking(|| event::poll(Duration::from_millis(16))) => { if let Ok(Ok(true)) = event_res -- cgit v1.2.3