Repository navigation
feat(render,weather): PixelArt shape + media_pixel + weather sprites - #260
Conversation
Introduces a small fixed-grid sprite shape paired with a truecolor half-block renderer (`▀`). Distinct from `Image`: `Image` carries a path rendered via terminal-graphics protocols (kitty / sixel / iTerm2); `PixelArt` carries inline RGBA data that works in any 24-bit-colour terminal. Pixels with `a = 0` blend into the theme background. Two pixel rows pack into one terminal cell, so a 16x16 sprite renders as 16 columns × 8 rows. Honours `align` (left / center / right), `max_width`, `max_height`; reports an in-band error for jagged rows; the centralised `is_empty_body` placeholder catches zero-row grids. Refs #259, #61 (media_pixel checkbox). Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Extends the `weather` fetcher (Open-Meteo now) with a `PixelArt` shape variant. Each WMO weather code maps to one of eight bundled 16x16 sprites: clear / mostly_clear / partly_cloudy / overcast / fog / rain / snow / thunderstorm. Unknown codes fall back to overcast so the renderer always has something to draw. Sprites are authored as ASCII grids with a per-sprite palette in `weather/sprites.rs`, decoded once via `OnceLock`. Keeps the binary text diff reviewable (no PNG assets to track) and bypasses any runtime PNG decode. Refs #259, #68 (weather extension). Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughAdds inline PixelArt payloads, a cached 16×16 weather sprite catalog mapped from WMO codes, a media_pixel terminal half-block renderer, and integrates PixelArt into the weather fetcher, samples, read-store, and snapshot preview config. ChangesPixel Art Sprite Feature
Sequence DiagramsequenceDiagram
participant WMOCode as Weather Code
participant SpriteCatalog as Sprite Catalog
participant PixelArtData as PixelArtData
participant MediaPixelRenderer as Media Pixel Renderer
participant TerminalBuffer as Terminal Buffer
WMOCode->>SpriteCatalog: sprite_for_code(code)
SpriteCatalog->>PixelArtData: return cached PixelArtData + label
PixelArtData->>MediaPixelRenderer: render(Body::PixelArt)
MediaPixelRenderer->>MediaPixelRenderer: sample top and bottom pixels per cell
MediaPixelRenderer->>MediaPixelRenderer: resolve transparent pixels to theme bg
MediaPixelRenderer->>TerminalBuffer: set half-block glyph + fg/bg truecolor
TerminalBuffer->>TerminalBuffer: display sprite in terminal buffer
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related issues
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (3)
src/samples.rs (1)
52-53: ⚡ Quick winInclude
Shape::PixelArtin the canonical-sample shape test matrix.
canonical_samplenow supports PixelArt (Line 52), butcanonical_sample_matches_requested_shapestill skips it. Adding it there prevents silent drift between sample fallback and shape routing.Suggested test update
@@ fn canonical_sample_matches_requested_shape() { Shape::Bars, + Shape::PixelArt, Shape::Calendar,Also applies to: 199-216
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/samples.rs` around lines 52 - 53, The test matrix skip logic in canonical_sample_matches_requested_shape omits Shape::PixelArt while canonical_sample now returns PixelArt (see Shape::PixelArt and pixel_art_sample), causing a mismatch; update the match arms in canonical_sample_matches_requested_shape to include Shape::PixelArt alongside the other shapes (and likewise add PixelArt to the other match block referenced in the later section around the 199-216 region) so the test covers PixelArt and the routing/fallback behavior remains consistent.src/payload.rs (1)
239-284: ⚡ Quick winAdd serde contract tests for
PixelArtpayloads.
PixelArtwas added to the wire format, but this file’s tests don’t currently pin its shape-tag round-trip or alpha-default behavior (aomitted =>255). That leaves cache/compat regressions unguarded.Suggested test additions
@@ #[test] + fn pixel_art_round_trips_and_shape_tag_is_stable() { + let p = bare(Body::PixelArt(PixelArtData { + pixels: vec![vec![PixelColor::opaque(255, 0, 0)]], + label: Some("demo".into()), + })); + assert_eq!(p, round_trip(&p)); + let v: serde_json::Value = serde_json::to_value(&p).unwrap(); + assert_eq!(v["shape"], "pixel_art"); + } + + #[test] + fn pixel_color_alpha_defaults_to_opaque_when_omitted() { + let c: PixelColor = serde_json::from_str(r#"{"r":1,"g":2,"b":3}"#).unwrap(); + assert_eq!(c.a, 255); + } + + #[test] + fn transparent_alpha_round_trips() { + let c = PixelColor::TRANSPARENT; + let s = serde_json::to_string(&c).unwrap(); + let back: PixelColor = serde_json::from_str(&s).unwrap(); + assert_eq!(back, c); + } + + #[test]🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/payload.rs` around lines 239 - 284, Add serde contract tests that verify PixelArt payloads (PixelArtData) round-trip their shape/tag through the wire and that PixelColor's alpha defaulting works: serialize a PixelArtData with PixelColor entries missing the `a` field and ensure deserializing yields a PixelColor with a == 255 (use PixelColor::opaque or check opaque_alpha via PixelColor::opaque) and that a transparent pixel (PixelColor::TRANSPARENT) round-trips correctly; also include a test that the serialized shape/tag for PixelArtData is stable across round-trip. Locate tests exercising PixelArtData, PixelColor, and their serde behaviour and add assertions that deserializing serialized JSON without `a` produces opaque alpha and that labels/pixel grid structure round-trip unchanged.src/render/mod.rs (1)
396-433: ⚡ Quick winExtend shape/renderer regression tests for PixelArt.
You wired
media_pixelandShape::PixelArtcorrectly, but the two coverage tables (registry_resolves_all_builtins,default_renderer_covers_every_shape) still omit them. That makes future breakage easy to miss.Suggested test updates
@@ fn registry_resolves_all_builtins() { "media_image", + "media_pixel", @@ fn default_renderer_covers_every_shape() { Shape::Image, + Shape::PixelArt, Shape::Calendar,🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/render/mod.rs` around lines 396 - 433, Update the two regression tests so PixelArt is included: in the test named registry_resolves_all_builtins add "media_pixel" (the renderer registered via media_pixel::MediaPixelRenderer) to the expected builtins list/check so the registry resolution assertion covers it, and in default_renderer_covers_every_shape include Shape::PixelArt (which should resolve via default_renderer_for to "media_pixel") in the set of shapes asserted to have default renderers; run the tests to confirm both registry_resolves_all_builtins and default_renderer_covers_every_shape now account for PixelArt.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@xtask/src/snapshots.rs`:
- Line 149: The preview canvas for PixelArt (Shape::PixelArt mapped to
"weather") is being clipped because renderer_dimensions() still falls back to
(40, 5) for media_pixel; update renderer_dimensions() to return a taller canvas
for MediaType::MediaPixel (e.g., (40, 10) or (40, 12)) so a 16×16 sprite plus
optional label fits without truncation. Locate the renderer_dimensions() match
arm for MediaType::MediaPixel and change the returned tuple accordingly so
PixelArt previews are not clipped.
---
Nitpick comments:
In `@src/payload.rs`:
- Around line 239-284: Add serde contract tests that verify PixelArt payloads
(PixelArtData) round-trip their shape/tag through the wire and that PixelColor's
alpha defaulting works: serialize a PixelArtData with PixelColor entries missing
the `a` field and ensure deserializing yields a PixelColor with a == 255 (use
PixelColor::opaque or check opaque_alpha via PixelColor::opaque) and that a
transparent pixel (PixelColor::TRANSPARENT) round-trips correctly; also include
a test that the serialized shape/tag for PixelArtData is stable across
round-trip. Locate tests exercising PixelArtData, PixelColor, and their serde
behaviour and add assertions that deserializing serialized JSON without `a`
produces opaque alpha and that labels/pixel grid structure round-trip unchanged.
In `@src/render/mod.rs`:
- Around line 396-433: Update the two regression tests so PixelArt is included:
in the test named registry_resolves_all_builtins add "media_pixel" (the renderer
registered via media_pixel::MediaPixelRenderer) to the expected builtins
list/check so the registry resolution assertion covers it, and in
default_renderer_covers_every_shape include Shape::PixelArt (which should
resolve via default_renderer_for to "media_pixel") in the set of shapes asserted
to have default renderers; run the tests to confirm both
registry_resolves_all_builtins and default_renderer_covers_every_shape now
account for PixelArt.
In `@src/samples.rs`:
- Around line 52-53: The test matrix skip logic in
canonical_sample_matches_requested_shape omits Shape::PixelArt while
canonical_sample now returns PixelArt (see Shape::PixelArt and
pixel_art_sample), causing a mismatch; update the match arms in
canonical_sample_matches_requested_shape to include Shape::PixelArt alongside
the other shapes (and likewise add PixelArt to the other match block referenced
in the later section around the 199-216 region) so the test covers PixelArt and
the routing/fallback behavior remains consistent.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 24ce7523-f9ef-4011-8d8e-164532a852e6
📒 Files selected for processing (8)
src/fetcher/weather/mod.rssrc/fetcher/weather/now.rssrc/fetcher/weather/sprites.rssrc/payload.rssrc/render/media_pixel.rssrc/render/mod.rssrc/samples.rsxtask/src/snapshots.rs
| Shape::PointSeries => "weather", | ||
| Shape::Bars => "github_languages", | ||
| Shape::Image => "github_avatar", | ||
| Shape::PixelArt => "weather", |
There was a problem hiding this comment.
Add explicit snapshot canvas sizing for media_pixel to avoid clipped previews.
Line 149 enables PixelArt renderer previews via weather, but renderer_dimensions() still falls back to (40, 5) for media_pixel, which truncates a 16×16 sprite (~8 rows, plus optional label).
Suggested fix
@@ fn renderer_dimensions(renderer: &str) -> (u16, u16) {
"media_image" => (40, 5),
+ "media_pixel" => (40, 10),
"grid_calendar" => (28, 10),
@@ fn renderer_dimensions_match_documented_sizes() {
("media_image", (40, 5)),
+ ("media_pixel", (40, 10)),
@@ fn representative_fetcher_prefers_documented_examples() {
(Shape::Image, "github_avatar"),
+ (Shape::PixelArt, "weather"),
(Shape::Calendar, "clock"),🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@xtask/src/snapshots.rs` at line 149, The preview canvas for PixelArt
(Shape::PixelArt mapped to "weather") is being clipped because
renderer_dimensions() still falls back to (40, 5) for media_pixel; update
renderer_dimensions() to return a taller canvas for MediaType::MediaPixel (e.g.,
(40, 10) or (40, 12)) so a 16×16 sprite plus optional label fits without
truncation. Locate the renderer_dimensions() match arm for MediaType::MediaPixel
and change the returned tuple accordingly so PixelArt previews are not clipped.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #260 +/- ##
========================================
Coverage 95.62% 95.62%
========================================
Files 248 250 +2
Lines 67832 68372 +540
========================================
+ Hits 64865 65382 +517
- Misses 2967 2990 +23
🚀 New features to boost your workflow:
|
Three follow-on additions caught by the Phase 3 self-review pass on PR #260: - `registry_resolves_all_builtins` learns the `media_pixel` builtin. - `default_renderer_covers_every_shape` iterates `Shape::PixelArt`. - `xtask::snapshots::renderer_dimensions` overrides the default (40 × 5) with a tighter (20 × 5) box matched to the canonical 4 × 4 PixelArt sample plus its caption row. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
There was a problem hiding this comment.
♻️ Duplicate comments (1)
xtask/src/snapshots.rs (1)
84-86:⚠️ Potential issue | 🟠 Major | ⚡ Quick win
media_pixelsnapshot height is still too small for weather PixelArt previews.Line 86 uses
(20, 5), which clips 16×16 weather sprites rendered as half-blocks (~8 rows before caption). This breaks fetcher-page previews forweather+media_pixel; the test on Line 234 currently locks in that clipping behavior.Suggested fix
- // Canonical PixelArt sample is a 4x4 smiley (2 cells wide × 2 cells tall) with a - // one-line caption; (20, 5) gives breathing room without dwarfing the sprite. - "media_pixel" => (20, 5), + // Weather PixelArt sprites are 16x16 and render as ~8 terminal rows with half-blocks; + // keep headroom for caption and avoid clipping in fetcher-page previews. + "media_pixel" => (20, 10), @@ - ("media_pixel", (20, 5)), + ("media_pixel", (20, 10)),🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@xtask/src/snapshots.rs` around lines 84 - 86, The snapshot size for the "media_pixel" entry in snapshots.rs is too short vertically (currently "(20, 5)") and clips 16×16 weather sprites rendered as half-blocks; update the tuple for the "media_pixel" key to increase the height (e.g., change (20, 5) to something like (20, 10) or at least (20, 9)) so the full ~8 rows of pixel-art plus the caption fit without clipping, and run the snapshot tests that reference this snapshot to confirm the preview no longer truncates.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Duplicate comments:
In `@xtask/src/snapshots.rs`:
- Around line 84-86: The snapshot size for the "media_pixel" entry in
snapshots.rs is too short vertically (currently "(20, 5)") and clips 16×16
weather sprites rendered as half-blocks; update the tuple for the "media_pixel"
key to increase the height (e.g., change (20, 5) to something like (20, 10) or
at least (20, 9)) so the full ~8 rows of pixel-art plus the caption fit without
clipping, and run the snapshot tests that reference this snapshot to confirm the
preview no longer truncates.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 2cdc0c20-16e2-4bfa-aec6-287486be04be
📒 Files selected for processing (2)
src/render/mod.rsxtask/src/snapshots.rs
🚧 Files skipped from review as they are similar to previous changes (1)
- src/render/mod.rs
Adds PixelArt to `READ_STORE_SHAPES`, `from_json`, `from_toml`, and `empty_body`, plus a structured-cases entry exercising both formats. Users can now drop a sprite at `$HOME/.splashboard/store/<id>.json` and point a `basic_read_store` widget at it with `shape = "pixel_art"` — the escape hatch the PixelArt shape needed to stand on its own without depending on a network fetcher. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
The original SPRITE_FOG used 1-pixel-row bands; under media_pixel's half-block packing each cell ended up as `fg=fog / bg=transparent`, so the sprite read as a faint pinstripe instead of fog. Bands are now two pixel rows thick so each one packs into a single solid cell, with varied horizontal indents giving a drifting feel. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Implements #259.
Summary
PixelArtshape (payload::PixelArtData, row-major RGBA grid + optional label) +media_pixelrenderer that draws each cell as a truecolor▀half-block. Distinct fromImage/media_image: works in any 24-bit-colour terminal, no kitty / sixel / iTerm2 protocol dependency.weatherfetcher gains aPixelArtshape variant. Eight bundled 16x16 sprites cover the WMO buckets (clear, mostly_clear, partly_cloudy, overcast, fog, rain, snow, thunderstorm); unknown codes fall back to overcast.basic_read_storelearnsPixelArtso users can drop their own sprite JSON at$HOME/.splashboard/store/<id>.jsonwithout depending on a network fetcher.Sprites are authored as ASCII grids with per-sprite palettes in
weather/sprites.rs, decoded once viaOnceLock. PR diff stays text-only.Two pixel rows pack into one terminal cell, so a 16x16 sprite renders as 16 columns × 8 rows. Honours
align/max_width/max_height; jagged rows surface an in-band error; the sharedis_empty_bodyplaceholder catches zero-row grids.After merge: tick the
media_pixelcheckbox on #61 and update theweatherentry on #68.media_pixelreference (mirror of/reference/renderers/media/media_pixel/)Draws a small pixel-art sprite cell-by-cell with truecolor half-blocks. Works in any terminal with 24-bit colour. Two stacked pixels fit into one cell, so a 16x16 sprite renders as 16 columns × 8 rows. Transparent pixels (
a = 0) blend with the theme background.pixel_artOptions
alignmax_widthmax_heightTheme tokens
bga = 0) pixels.textCompatible fetchers
pixel_artbasic_read_store,weatherTest plan
cargo test --lib— 3245 pass, 0 failcargo test -p xtask— 2 passcargo clippy --all-targets -- -D warnings— cleancargo fmt --all -- --check— cleancargo run --bin splashboard -- catalog renderer media_pixel— option schema + compatible fetchers list correctbasic_read_storewidget consumes all 8 weather sprite JSONs over a 4×2 grid; eight buckets render in truecolor, transparent regions blend with theme bg, captions appear below each sprite.Summary by CodeRabbit
New Features
Tests
Chores