diff --git a/README.md b/README.md index dfbe5d6..f298bed 100644 --- a/README.md +++ b/README.md @@ -112,8 +112,9 @@ orientation, `T` to cycle the theme, and `Q` to open the quit confirmation. Fader editing exposes capture rules, group membership, separate controller/Learn/Unlearn actions for volume and mute, size, and visibility. Add opens a chooser for a new application fader, empty group, or separator. -New faders and groups open directly in the editor; delete asks for confirmation -and removes the selected fader and its unshared target, or the selected separator. +New faders and groups open directly in the editor and remain visible as offline +`DRAFT` rows until Save activates them. Delete asks for confirmation and removes +the selected fader and its unshared target, or the selected separator. Config → Active profile opens the profile switcher. Config → Reset active profile provides an emergency return to safe defaults; confirming it immediately saves and activates the reset and keeps a `.reset.bak` diff --git a/architecture.md b/architecture.md index e031e3c..cd77727 100644 --- a/architecture.md +++ b/architecture.md @@ -523,11 +523,14 @@ The selected main-list entry can be moved directly. `A` opens a chooser for an application fader, group, or separator. Creating an application fader adds its application target with a deliberately non-matching exact selector, while a new group starts empty in absolute mode; both operations add a visible layout entry -and open the field-oriented fader editor. `D` confirms removal of either a -separator or a fader with its bindings and layout entry. A fader's application -or group target is also removed when no other fader owns it; applications still -referenced by a group are retained. These compound edits validate and publish as -one draft transaction, so no dangling intermediate configuration is observable. +and open the field-oriented fader editor. Because draft targets do not exist in +the active runtime yet, the TUI synthesizes a non-writable `DRAFT` row labeled +"save to activate" until Save publishes the real online or offline object. `D` +confirms removal of either a separator or a fader with its bindings and layout +entry. A fader's application or group target is also removed when no other fader +owns it; applications still referenced by a group are retained. These compound +edits validate and publish as one draft transaction, so no dangling intermediate +configuration is observable. The draft must still be saved before it becomes active. A centered separator dialog edits its name, size, and decoration. Names may be diff --git a/task.md b/task.md index f9653c6..3cdf124 100644 --- a/task.md +++ b/task.md @@ -468,7 +468,9 @@ Dependencies: M8, M2, M1. editor, IPC/server, and confirmation/cancellation paths are regression-tested. Mixer `A` now chooses a new application fader, empty absolute group, or separator. Compound application/group creation adds the target, fader, and - visible layout entry atomically before opening its guided editor. Generic `D` + visible layout entry atomically before opening its guided editor. New targets + remain visible as non-writable DRAFT rows with a Save-to-activate explanation + until activation replaces them with runtime objects. Generic `D` confirms removal of a fader and its unshared target or a separator. The new chooser, name editor, and confirmation popup are covered at tiny terminal sizes, completing the remaining object-creation acceptance. diff --git a/tui/src/lib.rs b/tui/src/lib.rs index 255a9eb..97f6029 100644 --- a/tui/src/lib.rs +++ b/tui/src/lib.rs @@ -32,6 +32,7 @@ const CLIENT_IDLE_REFRESH: Duration = Duration::from_millis(250); const CLIENT_PENDING_REFRESH: Duration = Duration::from_millis(20); const CLIENT_SHUTDOWN_GRACE: Duration = Duration::from_millis(25); const MAX_BUFFERED_MUTE_EDGES: usize = 128; +const DRAFT_ITEM_DETAIL: &str = "draft · save to activate"; #[derive(Clone, Copy, Debug, Eq, Ord, PartialEq, PartialOrd)] pub enum MixerObjectKind { @@ -1503,6 +1504,52 @@ fn mixer_viewport( (start, extents) } +fn add_draft_mixer_items(snapshot: &mut MixerSnapshot) { + if !snapshot.configuration.dirty { + return; + } + let targets = snapshot + .configuration + .faders + .iter() + .map(|fader| fader.target.clone()) + .collect::>(); + for target in targets { + if snapshot.items.iter().any(|item| item.id == target) { + continue; + } + let label = match target.kind { + MixerObjectKind::Application => snapshot + .configuration + .applications + .iter() + .find(|application| application.id == target.id) + .map(|application| application.label.clone()), + MixerObjectKind::Group => snapshot + .configuration + .groups + .iter() + .find(|group| group.id == target.id) + .map(|group| group.label.clone()), + MixerObjectKind::Output => None, + } + .unwrap_or_else(|| target.id.clone()); + snapshot.items.push(MixerItem { + id: target, + label, + detail: DRAFT_ITEM_DETAIL.to_owned(), + gain: None, + gain_mixed: false, + muted: None, + mute_mixed: false, + pending: false, + pickup: Some(PickupStatus::Unavailable), + writable: false, + error: None, + }); + } +} + impl LiveTui { pub fn new(mut client: C) -> io::Result { let snapshot = client.snapshot()?; @@ -1517,10 +1564,11 @@ impl LiveTui { fn from_snapshot( client: C, - snapshot: MixerSnapshot, + mut snapshot: MixerSnapshot, theme: ThemeName, theme_override: bool, ) -> Self { + add_draft_mixer_items(&mut snapshot); Self { client, snapshot, @@ -1576,7 +1624,7 @@ impl LiveTui { } } - fn replace_snapshot(&mut self, snapshot: MixerSnapshot) { + fn replace_snapshot(&mut self, mut snapshot: MixerSnapshot) { let selected_id = self.selected_layout_id(); self.client_error.clone_from(&snapshot.error); if self.theme_override { @@ -1586,6 +1634,7 @@ impl LiveTui { } else { self.theme = snapshot.configuration.theme; } + add_draft_mixer_items(&mut snapshot); self.snapshot = snapshot; self.selected = selected_id .and_then(|id| self.mixer_rows().iter().position(|row| row.id() == id)) @@ -4495,6 +4544,8 @@ impl LiveTui { }; let state = if item.error.is_some() { "ERROR" + } else if item.detail == DRAFT_ITEM_DETAIL { + "DRAFT" } else if item.gain.is_none() { "OFFLINE" } else if item.mute_mixed || item.gain_mixed { @@ -4671,7 +4722,9 @@ impl LiveTui { let percent = item .gain .map_or(0, |gain| (gain.clamp(0.0, 1.0) * 100.0).round() as u16); - let state = if item.gain.is_none() { + let state = if item.detail == DRAFT_ITEM_DETAIL { + "DRAFT" + } else if item.gain.is_none() { "OFFLINE" } else if item.mute_mixed || item.gain_mixed { "MIXED" @@ -5376,7 +5429,17 @@ mod tests { } app.handle_key_event(press(KeyCode::Enter)); assert!(app.fader_editor.is_some()); + assert_eq!(app.mixer_rows()[app.selected].id(), "chat-fader"); app.handle_key_event(press(KeyCode::Esc)); + let mut draft_buffer = Buffer::empty(area); + (&app).render(area, &mut draft_buffer); + let draft_rendered = draft_buffer + .content + .iter() + .map(|cell| cell.symbol()) + .collect::(); + assert!(draft_rendered.contains("DRAFT")); + assert!(draft_rendered.contains("save to activate")); app.handle_key_event(press(KeyCode::Char('a'))); app.handle_key_event(press(KeyCode::Down));