From 9b7ebb4bb1d0558cab69f77482813be13f5a5e8b Mon Sep 17 00:00:00 2001 From: Dandaedre Date: Sun, 18 Oct 2026 21:54:54 +0200 Subject: [PATCH] feat: add Save and exit to M9.5 capture editor Validate capture selectors before submitting either edit path; retain invalid input with an inline error. Document draft-save semantics. Verification: cargo test -p tui (49 passed); cargo fmt --all -- --check; cargo check --workspace --all-targets --all-features; cargo test --workspace --all-targets --all-features --quiet; cargo test --workspace --doc --all-features; cargo clippy --workspace --all-targets --all-features -- -D warnings; cargo build --workspace --release --all-features; cargo build --workspace; cargo build --workspace --no-default-features; cargo build -p volume_lib --no-default-features --features pulse; cargo build -p midi --no-default-features --features midir. All passed. Hardware fixtures remain opt-in. --- architecture.md | 5 +++ docs/configuration.md | 6 +++ task.md | 3 ++ tui/src/lib.rs | 92 ++++++++++++++++++++++++++++++++++++++++--- 4 files changed, 100 insertions(+), 6 deletions(-) diff --git a/architecture.md b/architecture.md index 0aeb54f..6117c03 100644 --- a/architecture.md +++ b/architecture.md @@ -604,6 +604,11 @@ presents domain fields rather than a serialized command: Home/End, accept, and cancel controls; group faders instead present a member summary that opens a multi-select popup, plus the currently available group mode. + Capture also has a Save and exit row to submit field/mode changes without + reopening Pattern. Both submission paths validate the current selector using + the domain's bounded exact/regex rules before queueing the draft edit; invalid + input retains the form and an inline error. Configuration Save remains the + separate persistence/activation operation. - **Volume control:** controller selection and Learn MIDI. The learn prompt offers `U` to unbind the current volume assignment and `Esc` to cancel. - **Mute control:** controller selection and Learn MIDI, with the same prompt diff --git a/docs/configuration.md b/docs/configuration.md index f8e75c8..69760f2 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -127,6 +127,12 @@ Supported fields are `application.name`, `application.id`, `application.process.binary`, and `media.name`. Exact matches are whole-string and case-sensitive. Regexes use Rust's bounded `regex` syntax. +The capture editor's **Save and exit** row validates and saves the current +field, match mode and pattern to the draft without reopening the pattern popup. +Invalid patterns leave the editor open with an error. **Esc** cancels local +capture changes; use the configuration **Save** action to persist and activate +accepted draft changes. + To capture YouTube playback by its reported media title, use: ```toml diff --git a/task.md b/task.md index 37a5d12..0bd01ef 100644 --- a/task.md +++ b/task.md @@ -451,6 +451,9 @@ Dependencies: M8, M2, M1. Field, Exact/Regex, and Pattern separately while preserving other selectors; Pattern opens a cursor-aware modal for local insertion and deletion rather than requiring the full value to be erased; + a Save and exit row validates and submits the current capture fields without + reopening Pattern. Invalid patterns retain the form and inline error; both + submission paths use domain validation before queueing the draft edit. groups edit application-fader membership in a checked multi-select popup and show the currently supported Absolute mode. Volume and Mute show separate controller and Learn MIDI actions. Learning opens a modal prompt for a fader diff --git a/tui/src/lib.rs b/tui/src/lib.rs index 47a98b4..5412c55 100644 --- a/tui/src/lib.rs +++ b/tui/src/lib.rs @@ -1315,6 +1315,7 @@ struct CaptureEditor { regex: bool, pattern: String, selected: usize, + error: Option, } #[derive(Clone, Debug, Eq, PartialEq)] @@ -2924,6 +2925,7 @@ impl LiveTui { regex, pattern, selected: 0, + error: None, }); } FaderEditorRow::GroupMembers { group, .. } => { @@ -3065,17 +3067,18 @@ impl LiveTui { }; match code { KeyCode::Up => editor.selected = editor.selected.saturating_sub(1), - KeyCode::Down => editor.selected = (editor.selected + 1).min(2), + KeyCode::Down => editor.selected = (editor.selected + 1).min(3), KeyCode::Left if editor.selected == 0 => editor.field = editor.field.saturating_sub(1), KeyCode::Right if editor.selected == 0 => editor.field = (editor.field + 1).min(3), KeyCode::Left | KeyCode::Right if editor.selected == 1 => editor.regex = !editor.regex, KeyCode::Enter if editor.selected < 2 => editor.selected += 1, - KeyCode::Enter => { + KeyCode::Enter if editor.selected == 2 => { self.pattern_editor = Some(PatternEditor { cursor: editor.pattern.chars().count(), value: editor.pattern.clone(), }); } + KeyCode::Enter => self.submit_capture_editor(), _ => {} } } @@ -3182,6 +3185,25 @@ impl LiveTui { let Some(editor) = &self.capture_editor else { return; }; + let field = match editor.field { + 0 => fader_core::MetadataField::ApplicationName, + 1 => fader_core::MetadataField::ApplicationId, + 2 => fader_core::MetadataField::ProcessBinary, + _ => fader_core::MetadataField::MediaName, + }; + let validated = if editor.regex { + fader_core::ApplicationSelector::regex(field, editor.pattern.clone()) + } else { + fader_core::ApplicationSelector::exact(field, editor.pattern.clone()) + }; + if let Err(error) = validated { + let message = error.to_string(); + if let Some(editor) = &mut self.capture_editor { + editor.error = Some(message.clone()); + } + self.client_error = Some(message); + return; + } let edit = ConfigurationEdit::SetApplicationSelector { id: editor.application.clone(), index: editor.selector, @@ -3197,7 +3219,13 @@ impl LiveTui { self.capture_editor = None; self.replace_snapshot(snapshot); } - Err(error) => self.client_error = Some(error.to_string()), + Err(error) => { + let message = error.to_string(); + if let Some(editor) = &mut self.capture_editor { + editor.error = Some(message.clone()); + } + self.client_error = Some(message); + } } } @@ -4215,8 +4243,9 @@ impl LiveTui { format!("Field {}", selector_field_name(editor.field)), format!("Match {}", if editor.regex { "Regex" } else { "Exact" }), format!("Pattern {}", editor.pattern), + "Save and exit".to_owned(), ]; - let lines = values + let mut lines = values .into_iter() .enumerate() .map(|(index, value)| { @@ -4231,14 +4260,16 @@ impl LiveTui { }) }) .collect::>(); + if let Some(error) = &editor.error { + lines.push(Line::from(format!("Error: {error}"))); + } Clear.render(popup, buf); Paragraph::new(Text::from(lines)) .block( Block::bordered() .title(" Edit capture ".fg(theme.accent).bold()) .title_bottom( - " ↑↓ field · ←→ choice · Enter next/edit pattern · Esc back " - .fg(theme.muted), + " ↑↓ select · ←→ choice · Enter edit/save · Esc cancel ".fg(theme.muted), ) .border_set(border::DOUBLE) .border_style(Style::default().fg(theme.accent)) @@ -6637,6 +6668,55 @@ mod tests { ))); } + #[test] + fn capture_save_and_exit_validates_without_reopening_pattern() { + let edits = Arc::new(Mutex::new(Vec::new())); + let mut app = LiveTui::new(LayoutClient { + snapshot: DemoClient::default().view(), + edits: Arc::clone(&edits), + }) + .unwrap(); + app.capture_editor = Some(CaptureEditor { + application: "music".into(), + selector: 0, + field: 0, + regex: false, + pattern: "[".into(), + selected: 0, + error: None, + }); + app.handle_key_event(press(KeyCode::Right)); + app.handle_key_event(press(KeyCode::Down)); + app.handle_key_event(press(KeyCode::Right)); + app.handle_key_event(press(KeyCode::Down)); + app.handle_key_event(press(KeyCode::Down)); + let area = Rect::new(0, 0, 100, 24); + let mut buffer = Buffer::empty(area); + (&app).render(area, &mut buffer); + let rendered = buffer + .content + .iter() + .map(|cell| cell.symbol()) + .collect::(); + assert!(rendered.contains("Save and exit")); + app.handle_key_event(press(KeyCode::Enter)); + assert!(app.capture_editor.is_some()); + assert!(app.pattern_editor.is_none()); + assert!(app.client_error.is_some()); + assert!(edits.lock().unwrap().is_empty()); + // Change only the match mode back to Exact, then save the same pattern. + app.handle_key_event(press(KeyCode::Up)); + app.handle_key_event(press(KeyCode::Up)); + app.handle_key_event(press(KeyCode::Left)); + app.handle_key_event(press(KeyCode::Down)); + app.handle_key_event(press(KeyCode::Down)); + app.handle_key_event(press(KeyCode::Enter)); + assert!(app.capture_editor.is_none()); + assert!( + matches!(edits.lock().unwrap().as_slice(), [ConfigurationEdit::SetApplicationSelector { field, pattern, regex: false, .. }] if field == "application.id" && pattern == "[") + ); + } + #[test] fn learn_popup_unbinds_only_its_action_and_keeps_controller_for_relearning() { let mut snapshot = DemoClient::default().view();