Skip to content

feat(scripting): API v6 cover-art widget and composable layouts (#396) - #403

Merged
LargeModGames merged 3 commits into
mainfrom
feat/plugin-api-v6-cover-art-layouts
Jul 27, 2026
Merged

LargeModGames merged 3 commits into
mainfrom
feat/plugin-api-v6-cover-art-layouts

Conversation

@LargeModGames

@LargeModGames LargeModGames commented Jul 26, 2026 •

Copy link
Copy Markdown
Owner

Summary

Closes #396.

Plugin custom 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. Bumps the scripting API to v6:

  • cover_art widget backed by the in-memory image the app already holds. No second
    download; the app keeps ownership of the graphics protocol, resizing, placement and cleanup.
    Gets its own protocol slot alongside playbar and fullscreen. fit is "contain" or
    "scale"; at most one per screen.
  • row / column containers, nestable, pure layout. Every widget takes a per-axis size
    hint (height/width, or height_percent/width_percent); the parent's axis picks which
    applies. Capped at 8 levels and 256 nodes.
  • scroll = false on paragraphs, so a header stays pinned while PageUp/PageDown move
    the rest.

PluginWidget becomes a wrapper struct { kind, width, height } rather than bolting width
onto each variant. All v5 widget tables keep parsing identically.

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 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. 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 and
CHANGELOG entries.

Testing

All three CI legs, clippy -D warnings and fmt clean on each:

  • cargo fmt --all -- --check
  • cargo clippy -- -D warnings / cargo test -> 751 passed
  • cargo 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 for cargo test -> 838 passed
    (audio-viz-cpal substituted for audio-viz locally; libspa-sys does not build on this machine)
  • cargo clippy --no-default-features --features telemetry -- -D warnings / cargo test -> 492 passed

New coverage:

  • layout_tree as a pure function: nesting, percentage splits, gauge axis behavior, empty containers
  • Draw path via TestBackend in both feature configurations, including that cover_art
    still parses and degrades to a labelled gap without the cover-art feature
  • The background-restore test is mutation-verified. It is what caught a Clear-scope bug where
    only the fitted image rect was cleared, so a previous track's larger image could leave a ghost
  • The shipped example is loaded and driven through the real Lua engine
  • Parser: v5 back-compat, conflicting size forms, percent out of range, depth and node caps at
    the boundary and one past, a second cover_art including a nested one, unknown fit/source

Manually 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 gauge now honors an explicit height. docs/scripting.md has always
said a widget's height takes exactly that many rows, but gauges ignored it and were pinned to
3 rows, which stays the default. A plugin that already set height on a gauge will see it
change size.

Resize::Crop (CSS cover) is deliberately not exposed: ratatui-image documents that it
overdraws 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

  • New Features
    • Upgraded the Lua scripting API to version 6.
    • Added cover_art support plus nested row/column layout containers for plugin screens.
    • Added cell/percentage-based widget sizing and introduced the now_playing example (cover art + synced lyrics).
  • Bug Fixes
    • Gauges now respect the configured height.
    • get_lyrics called during track_change no longer returns the previous track’s lyrics.
    • Paragraph headers configured with scroll = false stay fixed.
  • Documentation
    • Updated the scripting and widget guidance for API v6, including cover_art, containers, sizing, and scrolling behavior.

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.
@coderabbitai

coderabbitai Bot commented Jul 26, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 70d17038-2ca4-4667-902e-266af0619ae2

📥 Commits

Reviewing files that changed from the base of the PR and between ebc89ab and 7cba9a9.

📒 Files selected for processing (5)
  • docs/scripting.md
  • examples/plugins/README.md
  • examples/plugins/now-playing.lua
  • src/infra/scripting/api.rs
  • src/infra/scripting/tests.rs
🚧 Files skipped from review as they are similar to previous changes (5)
  • examples/plugins/README.md
  • examples/plugins/now-playing.lua
  • src/infra/scripting/tests.rs
  • src/infra/scripting/api.rs
  • docs/scripting.md

📝 Walkthrough

Walkthrough

API 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.

Changes

Plugin API v6 custom screens

Layer / File(s) Summary
API v6 widget contracts and parsing
src/core/plugin_api.rs, src/infra/scripting/api.rs, docs/scripting.md, CHANGELOG.md
Widget types now support rows, columns, cover art, sizing hints, and paragraph scroll settings. Recursive parsing validates nesting, node counts, cover-art options, and size hints.
Plugin layout and cover-art rendering
src/core/layout.rs, src/tui/cover_art.rs, src/tui/ui/player.rs, src/tui/ui/plugin_screen.rs, src/infra/scripting/tests.rs
Plugin screens flatten nested layouts into renderable leaves, honor sizing rules, render gauges and cover art, and maintain independent plugin image protocol state.
Current-track lyrics validation
src/core/plugin_api.rs, src/infra/scripting/engine.rs, src/infra/scripting/tests.rs, docs/scripting.md, CHANGELOG.md
Immediate lyrics delivery now requires stored lyrics to match the current playback identity, with regression coverage for track-change timing.
Now-playing example plugin
examples/plugins/now-playing.lua, examples/plugins/README.md, src/infra/scripting/tests.rs
Adds a screen combining current cover art, synchronized lyrics, pinned headers, periodic highlighting, and track-change reloads.

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
Loading

Possibly related PRs

  • LargeModGames/spotatui#378: Updates lyrics fetching and view synchronization, which is code-related to this PR’s current-track lyrics validation.
🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title uses a valid conventional-commit prefix and matches the PR's API v6 layout and cover-art work.
Linked Issues check ✅ Passed The PR implements the requested cover_art widget, row/column layouts, API v6, and compatibility with existing widget parsing.
Out of Scope Changes check ✅ Passed The changes stay focused on the v6 plugin screen feature and supporting docs, tests, and examples.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/plugin-api-v6-cover-art-layouts
✨ Simplify code
  • Create PR with simplified code
  • Commit simplified code in branch feat/plugin-api-v6-cover-art-layouts

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🧹 Nitpick comments (2)
src/tui/cover_art.rs (1)

183-185: 🚀 Performance & Scalability | 🔵 Trivial | 💤 Low value

Two full image clones per track change now.

store_decoded clones the decoded DynamicImage twice 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 first render_plugin from 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 = 0 slips through while percent = 0 is 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

📥 Commits

Reviewing files that changed from the base of the PR and between a12172e and ebc89ab.

📒 Files selected for processing (12)
  • CHANGELOG.md
  • docs/scripting.md
  • examples/plugins/README.md
  • examples/plugins/now-playing.lua
  • src/core/layout.rs
  • src/core/plugin_api.rs
  • src/infra/scripting/api.rs
  • src/infra/scripting/engine.rs
  • src/infra/scripting/tests.rs
  • src/tui/cover_art.rs
  • src/tui/ui/player.rs
  • src/tui/ui/plugin_screen.rs

Comment thread docs/scripting.md Resolved
Comment thread examples/plugins/now-playing.lua Resolved
LargeModGames and others added 2 commits July 26, 2026 12:21
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.
@LargeModGames
LargeModGames merged commit 0ac7b91 into main Jul 27, 2026
15 checks passed
@LargeModGames
LargeModGames deleted the feat/plugin-api-v6-cover-art-layouts branch July 27, 2026 03:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Plugin API: add cover-art widgets and composable layouts for custom screens

1 participant