Repository navigation
feat(scripting): API v6 cover-art widget and composable layouts (#396) - #403
Conversation
Custom plugin screens could only render a vertical stack of paragraph,
list and gauge widgets, so a plugin could neither place the cover art
the app has already downloaded nor put two widgets side by side. The
workarounds were all bad: re-download the image and write terminal
graphics escapes to /dev/tty (fighting Ratatui's rendering and cleanup),
a half-block approximation, or a native fork.
Bump the scripting API to v6:
* cover_art widget, backed by the in-memory image the app already holds.
A third protocol slot in CoverArt (plugin_state) is minted alongside
playbar and fullscreen, keeping the existing lockstep invariant. The
app retains ownership of downloading, decoding, protocol selection,
resizing, placement and cleanup. fit is "contain" (default) or
"scale"; Crop is deliberately not offered, since ratatui-image
documents that it overdraws characters over graphics and misbehaves on
some terminals. At most one per screen, enforced across the tree.
* row and column containers, nestable, pure layout with no border or
title. Every widget takes a per-axis size hint (height/width in cells,
or height_percent/width_percent); the parent's axis picks which
applies. Trees are capped at 8 levels and 256 nodes.
* paragraph gained scroll = false, so a header stays pinned while
PageUp/PageDown move the rest. Defaults to true, so v5 behavior is
unchanged.
PluginWidget becomes a wrapper struct { kind, width, height } rather
than bolting width onto each variant, which is what lets sizing and
recursion work without special cases. All v5 widget tables keep parsing
identically.
Behavior change: a gauge now honors an explicit height. docs/scripting.md
always documented that height takes exactly that many rows, but gauges
ignored it and were pinned to 3 rows, which stays the default.
Also fixes a pre-existing v5 bug found while testing the example:
spotatui.get_lyrics returned the previous track's lyrics when called
from a track_change handler. The runner ticks the script engine before
its shared track-change detector, so lyrics_status was still Found for
the outgoing track and the request resolved synchronously against it,
spending the one-shot callback before the new lyrics landed. The
immediate-delivery path now also checks that the stored lyrics belong to
the item playing right now.
Adds examples/plugins/now-playing.lua (cover art beside synchronized
lyrics) plus docs and CHANGELOG entries.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (5)
🚧 Files skipped from review as they are similar to previous changes (5)
📝 WalkthroughWalkthroughAPI v6 adds recursive row and column layouts, cover-art widgets, flexible sizing hints, updated paragraph scrolling, and gauge sizing. Rendering gains plugin-specific cover-art state. Lyrics requests validate track identity, and a now-playing example demonstrates the new screen API. ChangesPlugin API v6 custom screens
Estimated code review effort: 4 (Complex) | ~60 minutes Sequence Diagram(s)sequenceDiagram
participant LuaPlugin
participant ScriptAPI
participant PluginScreen
participant CoverArt
LuaPlugin->>ScriptAPI: set_screen(widget tree)
ScriptAPI->>PluginScreen: publish parsed widget tree
PluginScreen->>PluginScreen: compute nested layout and leaf rectangles
PluginScreen->>CoverArt: render current cover art with selected fit
CoverArt-->>PluginScreen: render image or status message
Possibly related PRs
🚥 Pre-merge checks | ✅ 4✅ Passed checks (4 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
✨ Simplify code
Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🧹 Nitpick comments (2)
src/tui/cover_art.rs (1)
183-185: 🚀 Performance & Scalability | 🔵 Trivial | 💤 Low valueTwo full image clones per track change now.
store_decodedclones the decodedDynamicImagetwice so each of the three protocols owns one, even when no plugin screen is open. Encoding stays lazy, so this is only the pixel buffer copy, but for a large cover it is a few megabytes of churn per track. If it shows up, the plugin protocol could be created lazily on firstrender_pluginfrom a retained source image.🤖 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/tui/cover_art.rs` around lines 183 - 185, Reduce unnecessary image cloning in the protocol setup around store_decoded: retain the decoded DynamicImage for the always-used image protocols, and defer creating the plugin protocol until render_plugin first needs it, using the retained source image. Preserve existing rendering behavior while avoiding a plugin-image clone when no plugin screen is open.src/infra/scripting/api.rs (1)
1247-1262: 🎯 Functional Correctness | 🔵 Trivial | 💤 Low value
cells = 0slips through whilepercent = 0is rejected.
Constraint::Length(0)produces an invisible widget with no error, so a plugin that computes a height and hits zero gets a silent blank instead of the same loud failure the percent path gives. Consider rejecting 0 cells too, or documenting that 0 means "hidden".♻️ Reject a zero cell count
- (Some(cells), None) => Ok(Some(plugin_api::PluginLength::Cells(cells))), + (Some(0), None) => Err(mlua::Error::RuntimeError(format!( + "{SET_SCREEN_FN}: '{cells_key}' must be at least 1" + ))), + (Some(cells), None) => Ok(Some(plugin_api::PluginLength::Cells(cells))),🤖 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/infra/scripting/api.rs` around lines 1247 - 1262, Update the set-screen length validation around the cells/percent match so a provided cells value of 0 returns an mlua runtime error, matching the percent validation behavior. Preserve valid positive cell counts, percent values from 1 through 100, and the existing mutual-exclusion and absent-value handling in the surrounding length parsing logic.
🤖 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 `@docs/scripting.md`:
- Around line 617-618: Update the sentence in the documentation describing
terminal requirements so the compound modifier uses a hyphen: change “Sixel
capable terminal” to “Sixel-capable terminal,” while preserving the rest of the
wording.
In `@examples/plugins/now-playing.lua`:
- Around line 1-3: Correct the layout documentation: in
examples/plugins/now-playing.lua lines 1-3, describe the example as using a row
layout, and in examples/plugins/README.md line 16, remove the column layout
claim. Do not add a column widget.
---
Nitpick comments:
In `@src/infra/scripting/api.rs`:
- Around line 1247-1262: Update the set-screen length validation around the
cells/percent match so a provided cells value of 0 returns an mlua runtime
error, matching the percent validation behavior. Preserve valid positive cell
counts, percent values from 1 through 100, and the existing mutual-exclusion and
absent-value handling in the surrounding length parsing logic.
In `@src/tui/cover_art.rs`:
- Around line 183-185: Reduce unnecessary image cloning in the protocol setup
around store_decoded: retain the decoded DynamicImage for the always-used image
protocols, and defer creating the plugin protocol until render_plugin first
needs it, using the retained source image. Preserve existing rendering behavior
while avoiding a plugin-image clone when no plugin screen is open.
🪄 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: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro Plus
Run ID: 00a31922-fd7d-4529-b9a4-699b037d4f58
📒 Files selected for processing (12)
CHANGELOG.mddocs/scripting.mdexamples/plugins/README.mdexamples/plugins/now-playing.luasrc/core/layout.rssrc/core/plugin_api.rssrc/infra/scripting/api.rssrc/infra/scripting/engine.rssrc/infra/scripting/tests.rssrc/tui/cover_art.rssrc/tui/ui/player.rssrc/tui/ui/plugin_screen.rs
Addresses the CodeRabbit review on #403. - Hyphenate the compound modifier in the cover-art terminal requirement. - The now-playing example only builds a row container, so drop the "column" claim from its header comment and from the examples README. - Document that a cell count of 0 hides a widget rather than rejecting it. `height` was already a v5 field that produced a Length(0) constraint, so erroring on 0 would break existing plugins; the percentage form has no such history and keeps its 1..=100 range. Adds a regression test pinning the v5 behavior.
Summary
Closes #396.
Plugin custom screens could only render a vertical stack of
paragraph,listandgaugewidgets, so a plugin could neither place the cover art the app has already downloaded nor put
two widgets side by side. Bumps the scripting API to v6:
cover_artwidget backed by the in-memory image the app already holds. No seconddownload; the app keeps ownership of the graphics protocol, resizing, placement and cleanup.
Gets its own protocol slot alongside playbar and fullscreen.
fitis"contain"or"scale"; at most one per screen.row/columncontainers, nestable, pure layout. Every widget takes a per-axis sizehint (
height/width, orheight_percent/width_percent); the parent's axis picks whichapplies. Capped at 8 levels and 256 nodes.
scroll = falseon paragraphs, so a header stays pinned whilePageUp/PageDownmovethe rest.
PluginWidgetbecomes a wrapper struct{ kind, width, height }rather than boltingwidthonto each variant. All v5 widget tables keep parsing identically.
Also fixes a pre-existing v5 bug found while testing the example:
spotatui.get_lyricsreturned the previous track's lyrics when called from a
track_changehandler. The runnerticks the script engine before its track-change detector, so
lyrics_statuswas stillFoundfor the outgoing track and the request resolved synchronously against it, spending the one-shot
callback. Immediate delivery now also checks the lyrics belong to the item playing right now.
Adds
examples/plugins/now-playing.lua(cover art beside synchronized lyrics), docs andCHANGELOG entries.
Testing
All three CI legs, clippy
-D warningsand fmt clean on each:cargo fmt --all -- --checkcargo clippy -- -D warnings/cargo test-> 751 passedcargo clippy --no-default-features --features telemetry,streaming,discord-rpc,cover-art,self-update,scripting,audio-viz-cpal,mpris,local-files,subsonic,internet-radio,youtube -- -D warnings/ same forcargo test-> 838 passed(
audio-viz-cpalsubstituted foraudio-vizlocally; libspa-sys does not build on this machine)cargo clippy --no-default-features --features telemetry -- -D warnings/cargo test-> 492 passedNew coverage:
layout_treeas a pure function: nesting, percentage splits, gauge axis behavior, empty containersTestBackendin both feature configurations, including thatcover_artstill parses and degrades to a labelled gap without the
cover-artfeatureClear-scope bug whereonly the fitted image rect was cleared, so a previous track's larger image could leave a ghost
the boundary and one past, a second
cover_artincluding a nested one, unknownfit/sourceManually verified on Kitty: art renders beside the lyrics, no hole or border damage, skipping a
track swaps both art and lyrics with no ghost, pinned header, fullscreen view round-trip, resize.
Additional notes
Behavior change: a
gaugenow honors an explicitheight.docs/scripting.mdhas alwayssaid a widget's
heighttakes exactly that many rows, but gauges ignored it and were pinned to3 rows, which stays the default. A plugin that already set
heighton a gauge will see itchange size.
Resize::Crop(CSScover) is deliberately not exposed: ratatui-image documents that itoverdraws characters over graphics and names Alacritty's sixel branch as misbehaving.
Follow-up worth considering: a plugin has no way to learn the rendered size of its own widgets,
so the example's lyric window is a fixed line count and cannot adapt to the pane height.
Summary by CodeRabbit
cover_artsupport plus nestedrow/columnlayout containers for plugin screens.now_playingexample (cover art + synced lyrics).height.get_lyricscalled duringtrack_changeno longer returns the previous track’s lyrics.scroll = falsestay fixed.cover_art, containers, sizing, and scrolling behavior.