Skip to content

Add sendspin-cli tui, a terminal remote for the running player - #120

Merged
chrisuthe merged 28 commits into
mainfrom
feat/tui
Nov 19, 2026
Merged

chrisuthe merged 28 commits into
mainfrom
feat/tui

Conversation

@chrisuthe

@chrisuthe chrisuthe commented Nov 10, 2026 •

Copy link
Copy Markdown
Member

Adds sendspin-cli tui, a terminal remote for the player that is already running. It attaches over the control socket, the same way sendspin-cli status does, and never plays audio or gets an identity of its own. When a server starts pairing, the code takes over the screen. The rest of the time it shows what is playing and drives playback with the Python TUI's keys. This is roadmap item 9. Design: docs/superpowers/specs/2026-11-10-tui-design.md; plan: docs/superpowers/plans/2026-11-10-tui.md.

The TUI

  • Attaching. sendspin-cli tui finds the player through the same --port, --control-socket and config-file rules as every other subcommand.
  • Pairing. Within about a second of a server starting an attempt, the screen clears to the 6-digit code in large block digits. When the terminal is too narrow for them, it shows plain spaced digits instead.
    • A pairing window waiting for pair confirm asks Y/N. After y, it says it is waiting for the server.
    • The outcome stays on screen for 3 s: "Paired with ...", "Pairing failed: " or "The server stopped pairing".
    • An outcome from before the TUI was opened is not replayed.
  • Now playing. Panels for now playing, volume, progress, playback, stream and server. Below 80 columns they stack.
    • Keys: space, ←/→, ↑/↓ (this player), [/] (group), m/M, r, x, g, ,/. and q.
    • p shows or hides the pairing token, on the main screen only.
  • When it can't attach.
    • No player: it says so and keeps checking.
    • Permission denied: it names the sudo ... --control-socket /run/sendspin-cli/control.sock command.
    • Older player: it says the player predates the TUI.
    • A poll that fails once does not detach it.
  • Requirements. It needs a terminal, and exits 1 otherwise. It is built on FTXUI v7.0.3, pinned by SHA, in a separate sendspin-cli-tui library. It is behind SENDSPIN_CLI_WITH_TUI, on by default. Core never includes FTXUI.

What the player gained for it

  • status gains new lines. Every existing line is unchanged.
    • last pairing: shows paired, failed with the reason, or abandoned. Without it, a wrong code fails faster than anything polling could see.
    • album:, group: and codec: show when they are known.
  • player-vol <0-100> and player-mute on|off set this endpoint's own level. They are answered locally, published to the server, and remembered. Under --fixed-volume they are refused with exit 2. vol and mute still address the group.
  • status-kv is status as key=value lines for scripts and the TUI. The first line is version=1, and the keys are documented and never renamed.
  • Every control exchange is now bounded to 3 s, including connect. A wedged player can no longer hang a subcommand or the TUI.

Testing

  • Windows (clang-cl Release, -Werror, static CRT): 596/596 tests and smoke_test_windows.ps1 pass. The format check is clean.
  • Linux (ubuntu:24.04, gcc, -Werror, every backend):
    • It builds clean.
    • 633/636 tests pass. The 3 failures are StateStore permission tests that also fail on main in the same root container.
    • smoke_test.sh passes, as a non-root user.
  • Tests added:
    • the pairing tracker against the library's real callback order;
    • the status-kv round trip, newline injection, and unknown and missing keys;
    • the exchange, including a player that never answers and a full accept backlog (Linux);
    • the TUI model: screens, keys, clamps, the pairing baseline across launch and reattach, the code taking priority over an open window, and the narrow fallback;
    • smoke checks for player-vol, player-mute, status-kv and --fixed-volume.
  • By hand on Windows: the TUI attaches, drops to the no-player screen when the player stops, and reattaches within 1.5 s. tui without a TTY exits 1.

Binary size: Windows +476 KB (2.27 MB to 2.74 MB); Linux +861 KB (2.84 MB to 3.70 MB).

Still to check by hand

  • A live pairing from Music Assistant: a wrong code, a right code, and a Y/N attempt where you press y.
  • Every key against a playing server.
  • Windows Terminal, the classic console host, and SSH to Linux.
  • A 40×12 window.
  • The full CI matrix with the TUI on: armv6, arm32, macOS and nomdns.

Known, not addressed here

  • On Windows, about 1 in 16 control exchanges gets no reply within 3 s, although the player applies the change. This already happens on main, and it affects status too. It needs its own look at how the player closes the socket on Windows.
  • Deferred to the roadmap:
    • access without sudo under the system service (a sendspin-cli group with a 0660 socket);
    • artwork, the visualizer, colour theming and a server picker.

Compatibility

Nothing breaks for CLI users. Everything here is additive: new tui, status-kv, player-vol and player-mute subcommands, and new last pairing, codec, album and group lines in status. Existing lines, flags and defaults are unchanged. A control exchange is now bounded by a single 3 s deadline across connect, write and read; before, each step had its own bound.

A player that accepts the control connection and never answers used to
block exchange_control_request forever: the TUI stopped polling, its
progress bar froze, and quitting hung on the worker's join. Every send and
receive on the client socket now gives up after 3 s with "the player did
not answer within 3 s", and the TUI's 250 ms tick runs on a thread that
does no socket I/O.
The library keeps the pairing window open until the attempt concludes, so
an attempt let past it showed its code behind "Y to allow, N to refuse",
and after y the prompt stayed up, where a following n cancelled the attempt
just allowed. A code now outranks the window, and once y has gone out the
takeover says "Allowed -- waiting for the server..." and ignores y and n
until that attempt ends.
The 3 s bound was set only after connect(), and on Linux a blocking
AF_UNIX connect() to a wedged player's full accept backlog waits for room
for ever, so the TUI's worker, and q with it, could hang for good. The
bound is now set before connect(), and a connect that runs it out fails
as "the player did not answer within 3 s". Windows refuses a full backlog
at once and takes no bound for connect() from these options.

The worker also sent every queued request, the token and a poll without
looking at the stop flag in between, so a quit could wait out several
bounds. It now checks before each exchange.
A poll that timed out, broke off or did not parse detached the TUI, and the
next good poll rebaselined, so a pairing attempt that ended in between was
never shown: the code flashed to "No sendspin-cli player is running here"
and then to the main screen without a word. Such a poll now keeps the last
screen and the baseline and leaves the notice "The player did not answer
-- retrying"; only a socket that is gone or refused detaches.

After a real detach, a reattach to the same player (same client id, its
counter not gone backwards) treats an attempt that ended meanwhile as news
rather than history.
The dispatcher's new branches had no end-to-end check. Both smoke scripts
now set this player's volume and mute with no server and read them back
from status, check that status-kv leads with version=1, and check that
player-vol under --fixed-volume exits 2.
A local volume or mute change left no line in the log, unlike a local
delay. Both now log at INFO ("Player volume set to 30 locally", "Player
muted locally"), and the smoke scripts check for the lines.
A pairing with a server that has no name read "Paired with " and nothing
after it; it now falls back to the id, with "..." only when the id was
actually cut. The name seen while the attempt was under way is kept for
the outcome, since right after success the re-handshake can leave the
connected server unknown for a poll.

p toggled the token on the takeovers, where the footer that shows it is
hidden, and on the no-player screens, where its fetch could only fail and
left "unavailable" showing after the attach. It now does nothing off the
main screen.
Controlling-the-Player gains a tui row in its subcommand table and lists
status-kv among the commands answered locally with exit 0, and the prose
this branch lengthened is wrapped again. Using-the-TUI no longer calls the
system service's socket root-only: it belongs to the service account at
mode 0600, and root gets in because root ignores the mode.
On Windows a recv() already blocked on an AF_UNIX socket can miss the
player's close and wait forever (or until the 3 s bound), although the
reply has arrived. select() reports that end of stream at once, so the
client now waits for readability, against one overall deadline, before
each read. This also affected main, where a status could hang.

The full-backlog connect test is Linux-only: macOS, like Windows,
refuses such a connect at once.

Copilot AI 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.

🟡 Changes recommended

Unresolved timeout and TUI state-handling defects can exceed exchange bounds, prevent repeated key presses from accumulating, and disable consent controls after failed confirmations.

6 open issues
What changed in this PR

Adds sendspin-cli tui as a terminal remote for the existing player, using the control socket without starting another player or creating a separate identity.

Changes:

  • Adds playback controls, responsive status panels, pairing screens and attachment recovery.
  • Extends player controls with local volume/mute, machine-readable status, pairing outcomes and socket timeouts.
  • Adds unit and smoke coverage, optional FTXUI build integration, and user documentation.
File Description
tests/​tui_model_test.cpp Tests screens, keys, pairing state and token handling.
tests/​status_kv_test.cpp Tests status serialization and parsing.
tests/​player_listener_test.cpp Tests local volume/mute and fixed-volume refusal.
tests/​pairing_tracker_test.cpp Tests pairing callback sequences and outcomes.
tests/​control_test.cpp Covers new commands and status fields.
tests/​control_exchange_test.cpp Tests socket replies and timeout scenarios.
src/​tui.h Declares the terminal UI entry point.
src/​tui.cpp Implements rendering, keyboard input and background exchanges.
src/​tui_model.h Defines UI state and model interfaces.
src/​tui_model.cpp Implements screen selection and control behavior.
src/​status_kv.h Defines the parsed status view and format interfaces.
src/​status_kv.cpp Implements versioned key-value status.
src/​socket_compat.h Adds portable timeout and readiness helpers.
src/​player_listener.h Exposes local volume/mute setters.
src/​player_listener.cpp Applies, publishes and persists local changes.
src/​pairing_tracker.h Defines pairing attempt tracking.
src/​pairing_tracker.cpp Records pairing lifecycle and outcomes.
src/​main.cpp Integrates TUI dispatch and expanded player status.
src/​control.h Adds commands, snapshot fields and exchange results.
src/​control_common.cpp Registers commands and formats new status fields.
src/​control_client.cpp Separates structured exchanges from printing and adds timeouts.
src/​audio_sink.h Adds the local volume-source category.
scripts/​smoke_test.sh Checks new controls and status on Linux.
scripts/​smoke_test_windows.ps1 Adds equivalent Windows smoke checks.
README.md Introduces commands and links TUI documentation.
docs/​wiki/​Using-the-TUI.md Documents screens, keys and connection handling.
docs/​wiki/​Pairing-a-Player.md Explains pairing outcomes and TUI usage.
docs/​wiki/​Controlling-the-Player.md Documents new commands and status format.
docs/​wiki/​_Sidebar.md Adds the TUI navigation link.
docs/​superpowers/​specs/​2026-11-10-tui-design.md Records the TUI design and constraints.
docs/​superpowers/​plans/​2026-11-10-tui.md Records implementation and validation steps.
docs/​ROADMAP.md Marks the TUI delivered and lists deferred features.
CMakeLists.txt Adds optional FTXUI integration, sources and tests.

Review effort: Balanced

Comment thread src/control_client.cpp Resolved
Comment thread src/tui.cpp Resolved
Comment thread src/tui.cpp Resolved
Comment thread src/tui.cpp Resolved
Comment thread src/tui_model.cpp Resolved
Comment thread src/tui_model.cpp Resolved
Fold pairing results into main's PairingListener and port status to the v0.10.0 accessors.
Also rebaseline pairing outcomes on a restart seen while attached, and move the position at the reported speed.
@chrisuthe
chrisuthe merged commit 08d851e into main Nov 19, 2026
38 of 41 checks passed
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.

2 participants