bread-theme: add an API to write pywal's colors.json cache from a Palette #24
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "feature/eco-22-write-wal-cache"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
bread-themecould read pywal'scolors.json(load_palette,from_wal_json) but had no way to write that format from an in-memoryPalette. This adds it.New public API in
bread_theme::palette(re-exported from the crate root):write_wal_cache(palette: &Palette, path: &Path) -> io::Result<()>- atomic (temp file then rename) write ofpalettein pywal'scolors.jsonshape, via the existingoutput::atomic_write.wal_cache_json(palette: &Palette) -> String- the same payload as a string, for tests and callers that want it without writing.wal_cache_path() -> PathBuf-~/.cache/wal/colors.json, the pathload_palettereads (previously the internalwal_path()had no public accessor).Format
All 16 ANSI slots plus
special(background/foreground/cursor),wallpaper, andalphaare written, so the file stays valid for every other pywal consumer on the system (terminal palettes, editor themes), not just the six accents bread-theme itself reads back.color8..color15mirrorcolor0..color7- bread-theme has no bright variants, which matches pywal's own behaviour when brightening is off.special.background/foregroundcome straight from thePalette(BOS's fixed dark values).Round-trips:
from_wal_json(&wal_cache_json(&p))gives backp'scolor1..color6and the fixed bg/fg/surface/overlay, same as any other wal JSON.Motivating consumer
breadpaper's
sync_focused_global(PAPER-2) holds a per-outputPalettebut still shells out to a secondwal -ion every focusedset_onjust to refresh~/.cache/wal/colors.json: a process spawn per switch, and it re-extracts from the image rather than using the palette it already computed, so the cache and breadpaper's per-output palette can drift. It can now callwrite_wal_cachedirectly. That breadpaper change is a separate follow-up in the breadpaper repo (kept out of this PR: different repo, one PR per issue).Verification
cargo build -p bread-theme,cargo test -p bread-theme --locked(114 pass, incl. 3 new: round-trip, all-16-slots-and-special, atomic-write-no-tmp-leftover),cargo clippy -p bread-theme --all-targets --locked -- -D warnings: cleanrustfmt --checkonpalette.rs: clean--features gtkand full---workspacepasses could not run locally (a disk-quota limit in the build sandbox on the GTK4 + ONNX dependency tree). My change is entirely in gtk-free code (palette.rs, one re-export line, the existingoutput::atomic_write), so CI's gtk and workspace matrix will cover it.Cargo.toml/Cargo.lockchange; CHANGELOG entry folded into the current unreleased## 0.7.11section.Closes #22