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.
This commit is contained in:
Dandaedre 2026-10-18 21:54:54 +02:00
parent 2b725ca82f
commit 9b7ebb4bb1
Signed by: Dandaedre
GPG Key ID: 440C6592E8A26D99
4 changed files with 100 additions and 6 deletions

View File

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

View File

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

View File

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

View File

@ -1315,6 +1315,7 @@ struct CaptureEditor {
regex: bool,
pattern: String,
selected: usize,
error: Option<String>,
}
#[derive(Clone, Debug, Eq, PartialEq)]
@ -2924,6 +2925,7 @@ impl<C: MixerClient> LiveTui<C> {
regex,
pattern,
selected: 0,
error: None,
});
}
FaderEditorRow::GroupMembers { group, .. } => {
@ -3065,17 +3067,18 @@ impl<C: MixerClient> LiveTui<C> {
};
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<C: MixerClient> LiveTui<C> {
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<C: MixerClient> LiveTui<C> {
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<C: MixerClient> LiveTui<C> {
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<C: MixerClient> LiveTui<C> {
})
})
.collect::<Vec<_>>();
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::<String>();
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();