feat: persist themes with a single save action

Store the selected theme in the validated profile, use it when the TUI starts without an explicit CLI override, and route both T and Config theme changes through revisioned edits. Remove the separate Apply operation so Save persists and activates the prepared configuration in one server-owned action. Bump the local IPC protocol for the new theme field and lifecycle.

Tests: cargo fmt --all -- --check; cargo check --workspace --all-targets --all-features; cargo test --workspace --all-targets --all-features; cargo test --workspace --doc --all-features; cargo clippy --workspace --all-targets --all-features -- -D warnings; cargo build --workspace --release --all-features; cargo check --workspace; cargo check --workspace --no-default-features; cargo check -p midi --no-default-features --features midir; cargo check -p volume_lib --no-default-features --features pulse
This commit is contained in:
Dandaedre 2026-10-15 22:29:56 +02:00
parent c0129cecfa
commit 556e0bdfe1
Signed by: Dandaedre
GPG Key ID: 440C6592E8A26D99
20 changed files with 361 additions and 170 deletions

View File

@ -37,13 +37,14 @@ cargo run --locked -p fader_master -- tui
```
Use Up/Down or J/K to select a configured fader or separator, Left/Right to
change its volume, M to toggle mute, T to cycle the built-in themes, and Q to
open the quit confirmation. Escape cancels the active editor or dialog and
change its volume, M to toggle mute, T to cycle the profile's theme draft, and Q
to open the quit confirmation. Escape cancels the active editor or dialog and
does not quit from the main screen. Pass `--theme dracula`, `nord`,
`gruvbox-dark`, `catppuccin-mocha`, or `solarized-dark` to choose an initial
theme. Offline objects remain visible, and aggregate rows show `MIXED` when
member state differs. See the hands-on checklist for the exact milestone scope
and restoration steps.
session theme. Save from Config to persist a theme selected with T. Offline
objects remain visible, and aggregate rows show `MIXED` when member state
differs. See the hands-on checklist for the exact milestone scope and
restoration steps.
The mixer is also the primary configuration surface. Shift+Up/Down reorders the
selected fader or separator; A adds a separator; E edits a selected fader or
@ -55,13 +56,15 @@ fader movement or button press from the selected controller. The editor also
provides per-fader Size (`Slim`, `Standard`, or `Thick`) and visibility. Slim
faders occupy one terminal row; Standard remains the compatible default. The
separator name is entered in a centered popup for both add and rename actions.
The Config tab is a settings/status page: change the session theme, switch the
The Config tab is a settings/status page: change the profile theme, switch the
persisted mixer layout between Vertical and Horizontal, select the profile's
default MIDI controller, restore individual hidden faders, inspect backend and
MIDI-device state, and apply or save the server-owned draft. Unassigned volume
and mute controls inherit that default for MIDI learn. Horizontal mode packs
fader cards side by side and keeps separators full-width. The old `Shift+h`
hidden-list mode and pipe-delimited object editors are no longer used.
MIDI-device state, and save the server-owned draft. Save both activates the
validated configuration and persists it; there is no separate Apply step.
Unassigned volume and mute controls inherit that default for MIDI learn.
Horizontal mode packs fader cards side by side and keeps separators full-width.
The old `Shift+h` hidden-list mode and pipe-delimited object editors are no
longer used.
# References

View File

@ -235,6 +235,7 @@ new_stream = "adopt"
[ui]
default_controller = "desk-left"
theme = "default"
[runtime]
poll_interval_ms = 10
@ -310,18 +311,20 @@ group controls remain a reserved future mode.
The live mixer revision and configuration-draft revision are independent.
Draft edits are serialized by the server, require the caller's expected draft
revision, and never mutate live routing or audio as a side effect. Successful
draft edits are explicitly marked unsaved until a later apply/save command.
draft edits are explicitly marked unsaved until a later Save command.
MIDI learn is scoped to one configured surface, logical fader, and action. While
armed, messages from that surface are withheld from normal routing; unrelated
surfaces continue normally. The first compatible CC or note press becomes a
validated draft binding, while cancellation restores routing immediately.
Apply and Save are separate editor actions. Apply rebuilds profile-derived
matching, groups, faders, pickup, and MIDI routing while retaining confirmed
audio observations and issuing no audio write. Save first compares the exact
on-disk bytes with the server's load/save baseline, then uses the atomic writer;
conflicts or persistence failures retain both the previous file and dirty draft.
Save is the only editor commit action. It first validates and prepares the
profile-derived matching, groups, faders, pickup, and MIDI routing, compares the
exact on-disk bytes with the server's load/save baseline, and uses the atomic
writer. After persistence succeeds, the server activates the prepared routing
while retaining confirmed audio observations and issuing no audio write.
Conflicts or persistence failures retain the previous file, live configuration,
and dirty draft.
The implemented atomic writer checks that its parent and any existing target
are owned by the effective user and are not symlinks. It creates mode-`0600`
@ -396,11 +399,12 @@ than being printed over the alternate screen.
Terminal colors come from semantic theme palettes rather than renderer-local
literals. The built-ins are Default, Dracula, Nord, Gruvbox Dark, Catppuccin
Mocha, and Solarized Dark. `tui --theme NAME` selects the initial palette and
`t` cycles themes for the current session; theme selection is presentation-only
and is not persisted in the audio profile. Each palette defines background,
foreground, accent/selection, secondary meter, muted, warning, error, and meter
track colors so status meaning remains consistent across themes.
Mocha, and Solarized Dark. `ui.theme` stores the profile palette, `t` cycles its
draft value, and Save persists it. `tui --theme NAME` remains a session-only
startup override. Theme selection never changes audio. Each palette defines
background, foreground, accent/selection, secondary meter, muted, warning,
error, and meter track colors so status meaning remains consistent across
themes.
The TUI is mixer-first rather than exposing the profile's normalized tables as
separate tabs. Its main list is an ordered presentation of logical faders and
@ -439,27 +443,29 @@ members. Absolute remains the only selectable group mode until the reserved
relative-mode runtime work is complete.
The secondary Config tab is not an alternative object editor. It presents
session theme selection, one-action restoration for each hidden fader, draft
Apply/Save state, active profile/backend status, MIDI-learn cancellation, and
MIDI-device diagnostics. Object and layout edits stay on the main mixer. There
is no separate hidden-fader mode: hidden rows disappear from the mixer and are
profile theme selection, one-action restoration for each hidden fader, unsaved
and Save state, active profile/backend status, MIDI-learn cancellation, and MIDI
device diagnostics. Object and layout edits stay on the main mixer. There is no
separate hidden-fader mode: hidden rows disappear from the mixer and are
restored from this settings page at their retained layout positions.
Every value presented as configuration is read from the server-owned validated
profile draft and every edit targets that same profile field. The TUI must not
invent parallel configuration defaults or overwrite unrelated fields; local
state is limited to clearly transient navigation and presentation choices such
as selection, open dialogs, and the session theme. `ui.default_controller`
references a configured MIDI surface. Unassigned volume and mute controls use
that surface for MIDI learn; an explicit binding continues to name its own
surface. The Config tab shows and changes this persisted default.
as selection, open dialogs, and an explicit CLI theme override.
`ui.default_controller` references a configured MIDI surface. Unassigned volume
and mute controls use that surface for MIDI learn; an explicit binding continues
to name its own surface. The Config tab shows and changes this persisted
default.
Draft changes do not affect live routing or audio. Apply and Save remain
distinct server-owned revisioned operations, validation errors preserve the
draft, MIDI learn reserves the selected action and suppresses its normal action,
and Unset removes only that fader/action binding. Device/backend status remains
available from the mixer without requiring a separate configuration table
browser.
Draft changes do not affect live routing or audio. Save is the single
server-owned revisioned commit: it persists the validated profile and activates
its routing and MIDI configuration. Validation or persistence errors preserve
the draft and the prior live configuration. MIDI learn reserves the selected
action and suppresses its normal action, and Unset removes only that
fader/action binding. Device/backend status remains available from the mixer
without requiring a separate configuration table browser.
MIDI learn reserves the selected control and suppresses its normal action while learning. Save sends a revisioned request to the server; it never writes files from the TUI. Restore terminal state on errors and exit. Use logs away from the active terminal display.

View File

@ -4,7 +4,7 @@ use toml_edit::{Array, ArrayOfTables, DocumentMut, InlineTable, Item, Table, Val
use crate::{
Action, ConfigError, FaderDensity, MessageKind, MixerOrientation, Profile, SelectorField,
TargetKind,
TargetKind, UiTheme,
};
/// Match expression used when creating an application selector.
@ -75,6 +75,28 @@ impl ProfileDocument {
})
}
/// Changes the saved terminal palette.
pub fn set_theme(&mut self, theme: UiTheme) -> Result<(), ConfigError> {
self.transaction(|document| {
if document.get("ui").is_none() {
document["ui"] = Item::Table(Table::new());
}
let ui = document
.get_mut("ui")
.and_then(Item::as_table_mut)
.ok_or_else(|| ConfigError::validation("ui", "must be a table"))?;
ui["theme"] = value(match theme {
UiTheme::Default => "default",
UiTheme::Dracula => "dracula",
UiTheme::Nord => "nord",
UiTheme::GruvboxDark => "gruvbox-dark",
UiTheme::CatppuccinMocha => "catppuccin-mocha",
UiTheme::SolarizedDark => "solarized-dark",
});
Ok(())
})
}
/// Changes one application's display label without rebuilding its table.
pub fn set_application_label(
&mut self,

View File

@ -26,7 +26,7 @@ pub use paths::{XdgEnvironment, XdgPaths};
pub use profile::{
Action, Adapter, Application, Audio, Binding, Fader, FaderDensity, Group, MessageKind,
MixerLayoutEntry, MixerOrientation, NewStreamPolicy, Profile, Selector, SelectorField,
StartupPolicy, Surface, TargetKind,
StartupPolicy, Surface, TargetKind, UiTheme,
};
pub use state::{
CachedObservation, DesiredWrite, PersistedState, ProfileState, StartupState, UiView,

View File

@ -41,6 +41,21 @@ struct UiSettings {
mixer_orientation: MixerOrientation,
#[serde(default, skip_serializing_if = "Option::is_none")]
default_controller: Option<String>,
#[serde(default)]
theme: UiTheme,
}
/// Built-in terminal palette saved with a profile.
#[derive(Clone, Copy, Debug, Default, Deserialize, Eq, PartialEq, Serialize)]
#[serde(rename_all = "kebab-case")]
pub enum UiTheme {
#[default]
Default,
Dracula,
Nord,
GruvboxDark,
CatppuccinMocha,
SolarizedDark,
}
/// Direction used to arrange fader displays in the mixer.
@ -398,6 +413,11 @@ impl Profile {
self.raw.ui.default_controller.as_deref()
}
/// Saved terminal palette for this profile.
pub const fn theme(&self) -> UiTheme {
self.raw.ui.theme
}
/// Validated bindings.
pub fn bindings(&self) -> &[Binding] {
&self.raw.bindings

View File

@ -130,7 +130,7 @@ fn editing_group_members_preserves_the_configured_volume_mode_field() {
#[test]
fn draft_sets_and_unsets_the_default_controller() {
let source = PROFILE.replace("[ui]\ndefault_controller = \"desk-left\"\n\n", "");
let source = PROFILE.replace("default_controller = \"desk-left\"\n", "");
let mut draft = ProfileDocument::parse(&source).unwrap();
draft.set_default_controller(Some("desk-left")).unwrap();
assert_eq!(
@ -148,6 +148,17 @@ fn draft_sets_and_unsets_the_default_controller() {
assert!(!draft.source().contains("default_controller"));
}
#[test]
fn draft_theme_edit_is_profile_backed() {
let mut draft = ProfileDocument::parse(PROFILE).unwrap();
draft.set_theme(fader_config::UiTheme::Nord).unwrap();
assert_eq!(
draft.preview().unwrap().theme(),
fader_config::UiTheme::Nord
);
assert!(draft.source().contains("theme = \"nord\""));
}
#[test]
fn draft_adds_bindings_and_rejects_duplicate_physical_controls() {
let mut draft = ProfileDocument::parse(PROFILE).unwrap();

View File

@ -119,12 +119,28 @@ fn default_controller_is_optional_and_must_reference_a_surface() {
);
assert_error_contains(Profile::parse(&missing), "unknown surface \"missing\"");
let without_default = EXAMPLE.replace("[ui]\ndefault_controller = \"desk-left\"\n\n", "");
let without_default = EXAMPLE.replace("default_controller = \"desk-left\"\n", "");
let profile =
Profile::parse(&without_default).expect("the default controller remains optional");
assert_eq!(profile.default_controller(), None);
}
#[test]
fn theme_is_profile_backed_and_rejects_unknown_values() {
let configured = EXAMPLE.replace("theme = \"default\"", "theme = \"dracula\"");
assert_eq!(
Profile::parse(&configured).unwrap().theme(),
fader_config::UiTheme::Dracula
);
let invalid = configured.replace("theme = \"dracula\"", "theme = \"hot_dog\"");
assert!(Profile::parse(&invalid).is_err());
assert_eq!(
Profile::parse(EXAMPLE).unwrap().theme(),
fader_config::UiTheme::Default
);
}
#[test]
fn runtime_poll_interval_defaults_and_validates_safe_overrides() {
let without_runtime = EXAMPLE.replace("[runtime]\npoll_interval_ms = 10\n\n", "");

View File

@ -5,6 +5,7 @@ new_stream = "adopt"
[ui]
default_controller = "apc-mini"
theme = "default"
[runtime]
poll_interval_ms = 10

View File

@ -5,6 +5,7 @@ new_stream = "adopt"
[ui]
default_controller = "desk-left"
theme = "default"
[runtime]
poll_interval_ms = 10

View File

@ -30,9 +30,9 @@ pub enum Command {
/// Override the XDG runtime socket path.
#[arg(long)]
socket: Option<PathBuf>,
/// Initial built-in color theme; press `t` to cycle themes while running.
#[arg(long, value_enum, default_value_t)]
theme: ThemeArgument,
/// Session-only initial color theme override.
#[arg(long, value_enum)]
theme: Option<ThemeArgument>,
},
/// Validate a profile without opening devices or changing audio.
Validate {

View File

@ -217,6 +217,23 @@ impl ConfigurationEditor {
ConfigurationEdit::SetDefaultController { surface } => {
self.document.set_default_controller(surface.as_deref())?
}
ConfigurationEdit::SetTheme { theme } => {
self.document.set_theme(match theme.as_str() {
"default" => fader_config::UiTheme::Default,
"dracula" => fader_config::UiTheme::Dracula,
"nord" => fader_config::UiTheme::Nord,
"gruvbox-dark" => fader_config::UiTheme::GruvboxDark,
"catppuccin-mocha" => fader_config::UiTheme::CatppuccinMocha,
"solarized-dark" => fader_config::UiTheme::SolarizedDark,
_ => {
return Err(ConfigError::Validation {
path: "ui.theme".to_owned(),
message: format!("unsupported theme {theme:?}"),
}
.into());
}
})?
}
ConfigurationEdit::AddSeparator {
id,
label,

View File

@ -3,7 +3,7 @@ use std::io::{self, Read, Write};
use serde::{Deserialize, Serialize, de::DeserializeOwned};
use thiserror::Error;
pub const PROTOCOL_VERSION: u16 = 15;
pub const PROTOCOL_VERSION: u16 = 16;
pub const MAX_FRAME_BYTES: usize = 64 * 1024;
/// Kind of mixer object addressed by a client.
@ -53,9 +53,6 @@ pub enum RequestCommand {
action: String,
},
CancelMidiLearn,
ApplyConfiguration {
expected_revision: u64,
},
SaveConfiguration {
expected_revision: u64,
},
@ -167,6 +164,9 @@ pub enum ConfigurationEdit {
SetDefaultController {
surface: Option<String>,
},
SetTheme {
theme: String,
},
AddSeparator {
id: String,
label: String,
@ -216,6 +216,7 @@ pub struct ConfigurationSnapshot {
pub profile_id: String,
pub mixer_orientation: MixerOrientation,
pub default_controller: Option<String>,
pub theme: String,
pub applications: Vec<ConfiguredApplication>,
pub groups: Vec<ConfiguredGroup>,
pub faders: Vec<ConfiguredFader>,

View File

@ -121,6 +121,15 @@ pub(crate) fn configuration_snapshot(
fader_config::MixerOrientation::Horizontal => crate::ipc::MixerOrientation::Horizontal,
},
default_controller: profile.default_controller().map(str::to_owned),
theme: match profile.theme() {
fader_config::UiTheme::Default => "default",
fader_config::UiTheme::Dracula => "dracula",
fader_config::UiTheme::Nord => "nord",
fader_config::UiTheme::GruvboxDark => "gruvbox-dark",
fader_config::UiTheme::CatppuccinMocha => "catppuccin-mocha",
fader_config::UiTheme::SolarizedDark => "solarized-dark",
}
.to_owned(),
applications: profile
.applications()
.iter()
@ -762,8 +771,7 @@ impl LiveMixerState {
"MIDI learn commands must be handled by the server owner".to_owned(),
));
}
RequestCommand::ApplyConfiguration { .. }
| RequestCommand::SaveConfiguration { .. } => {
RequestCommand::SaveConfiguration { .. } => {
return Err(LiveMixerError::Profile(
"configuration lifecycle commands must be handled by the server owner"
.to_owned(),

View File

@ -402,49 +402,34 @@ impl LocalServer {
command: crate::ipc::RequestCommand::Snapshot,
})
}
crate::ipc::RequestCommand::ApplyConfiguration { expected_revision }
if request.version == PROTOCOL_VERSION =>
{
if expected_revision != self.configuration.revision() {
Err(crate::live::LiveMixerError::Profile(format!(
"stale configuration revision {expected_revision}; current revision is {}",
self.configuration.revision()
)))
} else {
let profile = self.configuration.profile().map_err(|error| {
crate::live::LiveMixerError::Profile(error.to_string())
})?;
let midi = crate::midi_runtime::MidiRuntime::new(&profile)
.map_err(crate::live::LiveMixerError::Profile)?;
self.mixer
.reconfigure(&profile, Gain::new(profile.max_gain())?)?;
self.midi = midi;
self.applied_configuration_revision = self.configuration.revision();
self.publish_configuration(&profile, None);
self.mixer.request(ClientRequest {
version: request.version,
request_id,
command: crate::ipc::RequestCommand::Snapshot,
})
}
}
crate::ipc::RequestCommand::SaveConfiguration { expected_revision }
if request.version == PROTOCOL_VERSION =>
{
match self.configuration.save(expected_revision) {
Ok(()) => {
let profile = self.configuration.profile().map_err(|error| {
crate::live::LiveMixerError::Profile(error.to_string())
})?;
self.publish_configuration(&profile, None);
self.mixer.request(ClientRequest {
version: request.version,
request_id,
command: crate::ipc::RequestCommand::Snapshot,
})
}
Err(error) => Err(crate::live::LiveMixerError::Profile(error.to_string())),
if expected_revision != self.configuration.revision() {
return Err(crate::live::LiveMixerError::Profile(format!(
"stale configuration revision {expected_revision}; current revision is {}",
self.configuration.revision()
)));
}
let profile = self
.configuration
.profile()
.map_err(|error| crate::live::LiveMixerError::Profile(error.to_string()))?;
let midi = crate::midi_runtime::MidiRuntime::new(&profile)
.map_err(crate::live::LiveMixerError::Profile)?;
let max_gain = Gain::new(profile.max_gain())?;
self.configuration
.save(expected_revision)
.map_err(|error| crate::live::LiveMixerError::Profile(error.to_string()))?;
self.mixer.reconfigure(&profile, max_gain)?;
self.midi = midi;
self.applied_configuration_revision = self.configuration.revision();
self.publish_configuration(&profile, None);
self.mixer.request(ClientRequest {
version: request.version,
request_id,
command: crate::ipc::RequestCommand::Snapshot,
})
}
crate::ipc::RequestCommand::SwitchProfile { id, restore }
if request.version == PROTOCOL_VERSION =>
@ -823,6 +808,56 @@ mod tests {
assert_eq!(durable.active_profile().as_str(), "secondary");
}
#[test]
fn save_persists_and_activates_the_validated_draft() {
let root = tempdir().unwrap();
let source = include_str!("../../examples/profiles/desktop.toml");
let profile_path = root.path().join("desktop.toml");
fs::write(&profile_path, source).unwrap();
let mut server = LocalServer::pulse(
root.path().join("control.sock"),
Gain::UNITY,
ProfileDocument::parse(source).unwrap(),
profile_path.clone(),
root.path().join("config.toml"),
root.path().join("state.toml"),
)
.unwrap();
let edited = direct_request(
&mut server,
RequestCommand::EditConfiguration {
expected_revision: 0,
edit: crate::ipc::ConfigurationEdit::SetTheme {
theme: "dracula".into(),
},
},
);
let ResponseResult::Snapshot { snapshot } = edited.result else {
panic!("valid theme edit must produce a snapshot");
};
assert!(snapshot.configuration.dirty);
assert_eq!(snapshot.configuration.applied_revision, 0);
let saved = direct_request(
&mut server,
RequestCommand::SaveConfiguration {
expected_revision: 1,
},
);
let ResponseResult::Snapshot { snapshot } = saved.result else {
panic!("save must produce an activated snapshot");
};
assert!(!snapshot.configuration.dirty);
assert_eq!(snapshot.configuration.applied_revision, 1);
assert_eq!(snapshot.configuration.theme, "dracula");
assert!(
fs::read_to_string(profile_path)
.unwrap()
.contains("theme = \"dracula\"")
);
}
fn direct_request(
server: &mut LocalServer,
command: crate::ipc::RequestCommand,

View File

@ -18,8 +18,12 @@ fn main() -> Result<()> {
match Cli::parse().command {
Command::Tui { socket, theme } => {
let socket = socket.map_or_else(default_socket_path, Ok)?;
tui::run_live_with_theme(IpcMixerClient::new(socket), theme.theme())
.context("terminal UI failed")
if let Some(theme) = theme {
tui::run_live_with_theme(IpcMixerClient::new(socket), theme.theme())
.context("terminal UI failed")
} else {
tui::run_live(IpcMixerClient::new(socket)).context("terminal UI failed")
}
}
Command::Validate { config } => {
let profile = load_profile(&config)?;

View File

@ -104,6 +104,16 @@ impl IpcMixerClient {
}
},
default_controller: snapshot.configuration.default_controller,
theme: tui::ThemeName::from_config_name(&snapshot.configuration.theme)
.ok_or_else(|| {
io::Error::new(
io::ErrorKind::InvalidData,
format!(
"server returned unknown theme {:?}",
snapshot.configuration.theme
),
)
})?,
applications: snapshot
.configuration
.applications
@ -270,10 +280,6 @@ impl MixerClient for IpcMixerClient {
self.send(RequestCommand::CancelMidiLearn)
}
fn apply_configuration(&mut self, expected_revision: u64) -> io::Result<MixerSnapshot> {
self.send(RequestCommand::ApplyConfiguration { expected_revision })
}
fn save_configuration(&mut self, expected_revision: u64) -> io::Result<MixerSnapshot> {
self.send(RequestCommand::SaveConfiguration { expected_revision })
}
@ -373,6 +379,9 @@ fn configuration_edit(edit: TuiConfigurationEdit) -> crate::ipc::ConfigurationEd
TuiConfigurationEdit::SetDefaultController { surface } => {
IpcEdit::SetDefaultController { surface }
}
TuiConfigurationEdit::SetTheme { theme } => IpcEdit::SetTheme {
theme: theme.config_name().to_owned(),
},
TuiConfigurationEdit::AddSeparator {
id,
label,

View File

@ -66,7 +66,7 @@ fn tui_accepts_known_themes_and_rejects_unknown_names() {
.command,
Command::Tui {
socket: None,
theme: ThemeArgument::Default,
theme: None,
}
);
assert_eq!(
@ -75,7 +75,7 @@ fn tui_accepts_known_themes_and_rejects_unknown_names() {
.command,
Command::Tui {
socket: None,
theme: ThemeArgument::CatppuccinMocha,
theme: Some(ThemeArgument::CatppuccinMocha),
}
);
assert!(Cli::try_parse_from(["fader_master", "tui", "--theme", "hot-dog-stand"]).is_err());

22
task.md
View File

@ -300,9 +300,10 @@ Dependencies: M7, M4 for real use.
in shipped profiles without a separate product decision.
- [x] **M8.5 Built-in themes (stretch):** centralize semantic TUI colors and
provide Default, Dracula, Nord, Gruvbox Dark, Catppuccin Mocha, and Solarized
Dark palettes. `tui --theme` chooses the initial palette and `t` cycles it for
the current session. Tests: known CLI names parse, unknown names fail, cycling
wraps deterministically, and the selected palette/name reach rendered cells.
Dark palettes. Profiles persist the selected palette; `tui --theme` is an
optional session override and `t` edits the profile draft. Tests: known CLI
names parse, unknown names fail, cycling wraps deterministically, and the
selected palette/name reach rendered cells.
First live TUI slice verification on 2026-10-15: a real server selected Pulse
against PipeWire, reached `ready`, and published the active Qobuz playback stream
@ -353,10 +354,10 @@ Dependencies: M8, M2, M1.
The Config tab starts surface/fader/action-scoped learning with `L` and
cancels with `C`. Captured CC/note identity is added to the validated server
draft; conflicts are shown without changing the draft revision.
- [x] **M9.3 Apply/save/conflict:** server-owned revisioned edits, separate live apply and persistence. Tests: stale edits conflict, external file edits are not overwritten, comments survive save, write failure is shown as unsaved and leaves previous disk config usable.
`P` applies the validated draft without writing audio or disk; `S` atomically
saves it only when the on-disk bytes still match the server baseline. Draft,
live, and durable state remain separately visible after failures.
- [x] **M9.3 Save/conflict:** server-owned revisioned edits with one Save action
that persists and activates the validated draft. Tests: stale edits conflict,
external file edits are not overwritten, comments survive save, and write
failure leaves the previous disk and live configuration usable.
- [x] **M9.4 Mixer-first layout:** persist ordered logical-fader and separator
entries, synthesize declaration-order entries for old profiles, and retain
hidden faders in place. The main mixer can reorder either entry type, add/edit/
@ -396,13 +397,14 @@ Dependencies: M8, M2, M1.
surface.
- [ ] **M9.6 Single-screen configuration workflow:** remove the normalized
Config table browser once all its operations are reachable from the mixer,
keep Apply/Save and draft/live/durable status visible, and expose hidden-item
keep Save and draft/durable status visible, and expose hidden-item
restoration and device/backend diagnostics without a separate primary tab.
Tests: keyboard navigation and every modal work at small terminal sizes;
Escape backs out one level and never quits; invalid edits retain form input.
The normalized table browser and pipe-delimited object commands are removed.
Config is now a secondary settings/status page for session theme, hidden
restoration, Apply/Save, learning cancellation, and backend/device state.
Config is now a secondary settings/status page for the persisted profile
theme, hidden restoration, Save, learning cancellation, and backend/device
state.
Keep this item open until any remaining required object-creation workflow is
available from the mixer and its small-terminal acceptance passes.

View File

@ -89,6 +89,7 @@ pub struct ConfigurationSnapshot {
pub profile_id: String,
pub mixer_orientation: MixerOrientation,
pub default_controller: Option<String>,
pub theme: ThemeName,
pub applications: Vec<ConfiguredApplication>,
pub groups: Vec<ConfiguredGroup>,
pub faders: Vec<ConfiguredFader>,
@ -259,6 +260,9 @@ pub enum ConfigurationEdit {
SetDefaultController {
surface: Option<String>,
},
SetTheme {
theme: ThemeName,
},
AddSeparator {
id: String,
label: String,
@ -345,12 +349,6 @@ pub trait MixerClient {
"MIDI learn is unavailable",
))
}
fn apply_configuration(&mut self, _expected_revision: u64) -> io::Result<MixerSnapshot> {
Err(io::Error::new(
io::ErrorKind::Unsupported,
"configuration apply is unavailable",
))
}
fn save_configuration(&mut self, _expected_revision: u64) -> io::Result<MixerSnapshot> {
Err(io::Error::new(
io::ErrorKind::Unsupported,
@ -378,7 +376,6 @@ enum BufferedAction {
action: String,
},
CancelMidiLearn,
ApplyConfiguration,
SaveConfiguration,
}
@ -558,10 +555,6 @@ impl MixerClient for BufferedMixerClient {
self.queue_configuration_action(BufferedAction::CancelMidiLearn)
}
fn apply_configuration(&mut self, _expected_revision: u64) -> io::Result<MixerSnapshot> {
self.queue_configuration_action(BufferedAction::ApplyConfiguration)
}
fn save_configuration(&mut self, _expected_revision: u64) -> io::Result<MixerSnapshot> {
self.queue_configuration_action(BufferedAction::SaveConfiguration)
}
@ -692,7 +685,6 @@ fn execute_action<C: MixerClient>(
action,
} => client.start_midi_learn(surface.clone(), fader.clone(), action.clone()),
BufferedAction::CancelMidiLearn => client.cancel_midi_learn(),
BufferedAction::ApplyConfiguration => client.apply_configuration(configuration_revision),
BufferedAction::SaveConfiguration => client.save_configuration(configuration_revision),
};
match execute(client, confirmed.revision, confirmed.configuration.revision) {
@ -701,10 +693,8 @@ fn execute_action<C: MixerClient>(
if matches!(action, BufferedAction::SetVolume { .. })
|| (matches!(action, BufferedAction::EditConfiguration { .. })
&& first.kind() == io::ErrorKind::InvalidData)
|| (matches!(
action,
BufferedAction::ApplyConfiguration | BufferedAction::SaveConfiguration
) && first.kind() == io::ErrorKind::InvalidData)
|| (matches!(action, BufferedAction::SaveConfiguration)
&& first.kind() == io::ErrorKind::InvalidData)
|| (matches!(action, BufferedAction::ToggleMute { .. })
&& first.kind() == io::ErrorKind::InvalidData) =>
{
@ -766,13 +756,18 @@ fn discard_failed_action(state: &mut BufferedState, action: &BufferedAction) {
BufferedAction::Refresh => {}
BufferedAction::EditConfiguration { .. } => {}
BufferedAction::StartMidiLearn { .. } | BufferedAction::CancelMidiLearn => {}
BufferedAction::ApplyConfiguration | BufferedAction::SaveConfiguration => {}
BufferedAction::SaveConfiguration => {}
}
}
/// Runs the live terminal client and restores terminal state on every return.
pub fn run_live(client: impl MixerClient + Send + 'static) -> io::Result<()> {
run_live_with_theme(client, ThemeName::Default)
let client = BufferedMixerClient::spawn(client)?;
let mut app = LiveTui::new(client)?;
let mut terminal = ratatui::init();
let result = with_terminal_restore(ratatui::restore, || app.run(&mut terminal));
drop(app);
result
}
/// Runs the live terminal client with a selected built-in color theme.
@ -816,6 +811,7 @@ pub struct LiveTui<C> {
snapshot: MixerSnapshot,
selected: usize,
theme: ThemeName,
theme_override: bool,
exit: bool,
quit_confirmation: bool,
client_error: Option<String>,
@ -847,7 +843,6 @@ enum SettingsRow {
DefaultController,
HiddenFader { id: String, label: String },
CancelMidiLearn,
Apply,
Save,
}
@ -960,17 +955,29 @@ impl MixerRow<'_> {
}
impl<C: MixerClient> LiveTui<C> {
pub fn new(client: C) -> io::Result<Self> {
Self::with_theme(client, ThemeName::Default)
pub fn new(mut client: C) -> io::Result<Self> {
let snapshot = client.snapshot()?;
let theme = snapshot.configuration.theme;
Ok(Self::from_snapshot(client, snapshot, theme, false))
}
pub fn with_theme(mut client: C, theme: ThemeName) -> io::Result<Self> {
let snapshot = client.snapshot()?;
Ok(Self {
Ok(Self::from_snapshot(client, snapshot, theme, true))
}
fn from_snapshot(
client: C,
snapshot: MixerSnapshot,
theme: ThemeName,
theme_override: bool,
) -> Self {
Self {
client,
snapshot,
selected: 0,
theme,
theme_override,
exit: false,
quit_confirmation: false,
client_error: None,
@ -981,7 +988,7 @@ impl<C: MixerClient> LiveTui<C> {
capture_editor: None,
controller_picker: None,
controller_selections: BTreeMap::new(),
})
}
}
#[must_use]
@ -1013,6 +1020,13 @@ impl<C: MixerClient> LiveTui<C> {
fn replace_snapshot(&mut self, snapshot: MixerSnapshot) {
let selected_id = self.selected_layout_id();
self.client_error.clone_from(&snapshot.error);
if self.theme_override {
if snapshot.configuration.theme == self.theme {
self.theme_override = false;
}
} else {
self.theme = snapshot.configuration.theme;
}
self.snapshot = snapshot;
self.selected = selected_id
.and_then(|id| self.mixer_rows().iter().position(|row| row.id() == id))
@ -1110,7 +1124,7 @@ impl<C: MixerClient> LiveTui<C> {
return;
}
match key_event.code {
KeyCode::Char('t') => self.theme = self.theme.next(),
KeyCode::Char('t') => self.change_theme(self.theme.next()),
KeyCode::Tab => {
self.tab = match self.tab {
Tab::Mixer => Tab::Configuration,
@ -1304,7 +1318,6 @@ impl<C: MixerClient> LiveTui<C> {
if self.snapshot.configuration.learning.is_some() {
rows.push(SettingsRow::CancelMidiLearn);
}
rows.push(SettingsRow::Apply);
rows.push(SettingsRow::Save);
rows
}
@ -1324,7 +1337,6 @@ impl<C: MixerClient> LiveTui<C> {
KeyCode::Char('c') if self.snapshot.configuration.learning.is_some() => {
self.cancel_midi_learn()
}
KeyCode::Char('p') => self.apply_configuration(),
KeyCode::Char('s') => self.save_configuration(),
_ => {}
}
@ -1336,11 +1348,12 @@ impl<C: MixerClient> LiveTui<C> {
};
match row {
SettingsRow::Theme => {
self.theme = if forward {
let theme = if forward {
self.theme.next()
} else {
self.theme.previous()
};
self.change_theme(theme);
}
SettingsRow::MixerOrientation => {
self.apply_layout_edit(ConfigurationEdit::SetMixerOrientation {
@ -1377,7 +1390,6 @@ impl<C: MixerClient> LiveTui<C> {
self.clamp_selection();
}
SettingsRow::CancelMidiLearn if forward => self.cancel_midi_learn(),
SettingsRow::Apply if forward => self.apply_configuration(),
SettingsRow::Save if forward => self.save_configuration(),
_ => {}
}
@ -1390,14 +1402,10 @@ impl<C: MixerClient> LiveTui<C> {
}
}
fn apply_configuration(&mut self) {
match self
.client
.apply_configuration(self.snapshot.configuration.revision)
{
Ok(snapshot) => self.replace_snapshot(snapshot),
Err(error) => self.client_error = Some(error.to_string()),
}
fn change_theme(&mut self, theme: ThemeName) {
self.theme = theme;
self.theme_override = true;
self.apply_layout_edit(ConfigurationEdit::SetTheme { theme });
}
fn save_configuration(&mut self) {
@ -2018,8 +2026,8 @@ impl<C: MixerClient> Widget for &LiveTui<C> {
"select".fg(theme.secondary),
" ←→/Enter ".fg(theme.foreground),
"change".fg(theme.secondary),
" P/S ".fg(theme.foreground),
"apply/save".fg(theme.secondary),
" S ".fg(theme.foreground),
"save".fg(theme.secondary),
" Tab ".fg(theme.foreground),
"mixer".fg(theme.secondary),
" T ".fg(theme.foreground),
@ -2427,7 +2435,7 @@ impl<C: MixerClient> LiveTui<C> {
let config = &self.snapshot.configuration;
let mut lines = vec![
Line::from(format!(
"Profile: {}{} · draft {} · live {}{}",
"Profile: {}{} · revision {}{}",
config.profile_id,
if config.selection_saved {
""
@ -2435,7 +2443,6 @@ impl<C: MixerClient> LiveTui<C> {
" · selection unsaved"
},
config.revision,
config.applied_revision,
if config.dirty {
" · unsaved draft"
} else {
@ -2490,16 +2497,8 @@ impl<C: MixerClient> LiveTui<C> {
format!("Show hidden fader {label} [Enter]")
}
SettingsRow::CancelMidiLearn => "Cancel MIDI learn [Enter]".to_owned(),
SettingsRow::Apply => format!(
"Apply draft {}",
if config.revision == config.applied_revision {
"already live"
} else {
"[Enter]"
}
),
SettingsRow::Save => format!(
"Save draft {}",
"Save changes {}",
if config.dirty {
"[Enter]"
} else {
@ -3024,6 +3023,9 @@ mod tests {
ConfigurationEdit::SetDefaultController { surface } => {
self.snapshot.configuration.default_controller.clone_from(surface);
}
ConfigurationEdit::SetTheme { theme } => {
self.snapshot.configuration.theme = *theme;
}
ConfigurationEdit::AddSeparator {
id,
label,
@ -3275,6 +3277,19 @@ mod tests {
}));
}
#[test]
fn saved_profile_theme_is_used_without_a_cli_override() {
let mut snapshot = DemoClient::default().view();
snapshot.configuration.theme = ThemeName::Nord;
let app = LiveTui::new(LayoutClient {
snapshot,
edits: Arc::new(Mutex::new(Vec::new())),
})
.unwrap();
assert_eq!(app.theme(), ThemeName::Nord);
}
#[test]
fn live_mixer_renders_status_and_stream_at_typical_size() {
let mut app = LiveTui::new(DemoClient::default()).unwrap();
@ -3810,6 +3825,7 @@ mod tests {
profile_id: "desktop".into(),
mixer_orientation: MixerOrientation::Vertical,
default_controller: Some("desk-left".into()),
theme: ThemeName::Dracula,
applications: vec![ConfiguredApplication {
id: "browser".into(),
label: "Browser".into(),
@ -3875,8 +3891,8 @@ mod tests {
assert!(rendered.contains("Theme Default"));
assert!(rendered.contains("Default controller Desk controller"));
assert!(rendered.contains("Hidden faders none"));
assert!(rendered.contains("Apply draft"));
assert!(rendered.contains("Save draft"));
assert!(!rendered.contains("Apply draft"));
assert!(rendered.contains("Save changes"));
assert!(rendered.contains("Desk controller — connected · 20:0"));
assert!(!rendered.contains("Applications"));
}
@ -3919,6 +3935,9 @@ mod tests {
assert_eq!(
edits.lock().unwrap().as_slice(),
&[
ConfigurationEdit::SetTheme {
theme: ThemeName::Dracula
},
ConfigurationEdit::SetMixerOrientation {
orientation: MixerOrientation::Horizontal
},
@ -3930,7 +3949,7 @@ mod tests {
}
#[test]
fn configuration_tab_cancels_learning_and_applies_or_saves_the_draft() {
fn configuration_tab_cancels_learning_and_saves_the_draft() {
struct LearnClient {
snapshot: MixerSnapshot,
calls: Arc<Mutex<Vec<String>>>,
@ -3968,20 +3987,13 @@ mod tests {
self.snapshot.configuration.learning = None;
Ok(self.snapshot.clone())
}
fn apply_configuration(&mut self, expected_revision: u64) -> io::Result<MixerSnapshot> {
self.calls
.lock()
.unwrap()
.push(format!("apply:{expected_revision}"));
self.snapshot.configuration.applied_revision = expected_revision;
Ok(self.snapshot.clone())
}
fn save_configuration(&mut self, expected_revision: u64) -> io::Result<MixerSnapshot> {
self.calls
.lock()
.unwrap()
.push(format!("save:{expected_revision}"));
self.snapshot.configuration.dirty = false;
self.snapshot.configuration.applied_revision = expected_revision;
Ok(self.snapshot.clone())
}
}
@ -3997,12 +4009,8 @@ mod tests {
app.handle_key_event(press(KeyCode::Char('c')));
assert!(app.snapshot.configuration.learning.is_none());
app.handle_key_event(press(KeyCode::Char('2')));
app.handle_key_event(press(KeyCode::Char('p')));
app.handle_key_event(press(KeyCode::Char('s')));
assert_eq!(
calls.lock().unwrap().as_slice(),
&["cancel", "apply:0", "save:0"]
);
assert_eq!(calls.lock().unwrap().as_slice(), &["cancel", "save:0"]);
}
#[test]

View File

@ -14,6 +14,33 @@ pub enum ThemeName {
}
impl ThemeName {
/// Stable profile value used by IPC and TOML configuration.
#[must_use]
pub const fn config_name(self) -> &'static str {
match self {
Self::Default => "default",
Self::Dracula => "dracula",
Self::Nord => "nord",
Self::GruvboxDark => "gruvbox-dark",
Self::CatppuccinMocha => "catppuccin-mocha",
Self::SolarizedDark => "solarized-dark",
}
}
/// Parses a validated profile theme received over IPC.
#[must_use]
pub fn from_config_name(value: &str) -> Option<Self> {
match value {
"default" => Some(Self::Default),
"dracula" => Some(Self::Dracula),
"nord" => Some(Self::Nord),
"gruvbox-dark" => Some(Self::GruvboxDark),
"catppuccin-mocha" => Some(Self::CatppuccinMocha),
"solarized-dark" => Some(Self::SolarizedDark),
_ => None,
}
}
/// Human-readable theme name displayed by the TUI.
#[must_use]
pub const fn label(self) -> &'static str {