fix: confirm TUI quit requests
Make Q open an explicit confirmation dialog and reserve Escape for cancelling editors and dialogs. Update the rendered help and README controls accordingly.\n\nTests: cargo fmt --all -- --check\nTests: cargo check --locked --workspace --all-targets --all-features\nTests: cargo test --locked --workspace --all-targets --all-features\nTests: cargo test --locked --workspace --doc --all-features\nTests: cargo clippy --locked --workspace --all-targets --all-features -- -D warnings\nTests: cargo build --locked --workspace --release --all-features\nTests: cargo check --locked --workspace --all-targets\nTests: cargo check --locked --workspace --all-targets --no-default-features\nTests: cargo test --locked --workspace --all-targets --no-default-features
This commit is contained in:
parent
661b0b105a
commit
fbea588e67
13
README.md
13
README.md
|
|
@ -37,12 +37,13 @@ cargo run --locked -p fader_master -- tui
|
|||
```
|
||||
|
||||
Use Up/Down or J/K to select a configured application or group, Left/Right to
|
||||
change its volume, M to toggle mute, T to cycle the built-in themes, and Q or
|
||||
Escape to quit. 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.
|
||||
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
|
||||
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.
|
||||
|
||||
# References
|
||||
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ use ratatui::{
|
|||
style::{Style, Stylize},
|
||||
symbols::border,
|
||||
text::{Line, Text},
|
||||
widgets::{Block, Gauge, Paragraph, Widget, Wrap},
|
||||
widgets::{Block, Clear, Gauge, Paragraph, Widget, Wrap},
|
||||
};
|
||||
|
||||
const VOLUME_STEP: f64 = 0.05;
|
||||
|
|
@ -655,6 +655,7 @@ pub struct LiveTui<C> {
|
|||
selected: usize,
|
||||
theme: ThemeName,
|
||||
exit: bool,
|
||||
quit_confirmation: bool,
|
||||
client_error: Option<String>,
|
||||
tab: Tab,
|
||||
editor: Option<EditorInput>,
|
||||
|
|
@ -695,6 +696,7 @@ impl<C: MixerClient> LiveTui<C> {
|
|||
selected: 0,
|
||||
theme,
|
||||
exit: false,
|
||||
quit_confirmation: false,
|
||||
client_error: None,
|
||||
tab: Tab::Mixer,
|
||||
editor: None,
|
||||
|
|
@ -748,6 +750,14 @@ impl<C: MixerClient> LiveTui<C> {
|
|||
}
|
||||
|
||||
fn handle_key_event(&mut self, key_event: KeyEvent) {
|
||||
if self.quit_confirmation {
|
||||
match key_event.code {
|
||||
KeyCode::Char('y' | 'Y') => self.exit = true,
|
||||
KeyCode::Char('n' | 'N') | KeyCode::Esc => self.quit_confirmation = false,
|
||||
_ => {}
|
||||
}
|
||||
return;
|
||||
}
|
||||
if self.editor.is_some() {
|
||||
self.handle_editor_key(key_event.code);
|
||||
return;
|
||||
|
|
@ -815,7 +825,7 @@ impl<C: MixerClient> LiveTui<C> {
|
|||
Err(error) => self.client_error = Some(error.to_string()),
|
||||
}
|
||||
}
|
||||
KeyCode::Esc | KeyCode::Char('q') => self.exit = true,
|
||||
KeyCode::Char('q') => self.quit_confirmation = true,
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
|
@ -1097,7 +1107,7 @@ impl<C> Widget for &LiveTui<C> {
|
|||
"theme".fg(theme.secondary),
|
||||
" Tab ".fg(theme.foreground),
|
||||
"config".fg(theme.secondary),
|
||||
" Q/Esc ".fg(theme.foreground),
|
||||
" Q ".fg(theme.foreground),
|
||||
"quit".fg(theme.secondary),
|
||||
]),
|
||||
Tab::Configuration => Line::from(vec![
|
||||
|
|
@ -1117,7 +1127,7 @@ impl<C> Widget for &LiveTui<C> {
|
|||
"mixer".fg(theme.secondary),
|
||||
" T ".fg(theme.foreground),
|
||||
"theme".fg(theme.secondary),
|
||||
" Q/Esc ".fg(theme.foreground),
|
||||
" Q ".fg(theme.foreground),
|
||||
"quit".fg(theme.secondary),
|
||||
]),
|
||||
};
|
||||
|
|
@ -1129,6 +1139,37 @@ impl<C> Widget for &LiveTui<C> {
|
|||
.border_style(Style::default().fg(theme.muted)),
|
||||
)
|
||||
.render(footer, buf);
|
||||
|
||||
if self.quit_confirmation {
|
||||
let width = area.width.min(46);
|
||||
let height = area.height.min(5);
|
||||
let popup = Rect::new(
|
||||
area.x + area.width.saturating_sub(width) / 2,
|
||||
area.y + area.height.saturating_sub(height) / 2,
|
||||
width,
|
||||
height,
|
||||
);
|
||||
Clear.render(popup, buf);
|
||||
Paragraph::new(Text::from(vec![
|
||||
Line::from("Quit fader_master?").bold(),
|
||||
Line::from(vec![
|
||||
" Y ".fg(theme.foreground).bold(),
|
||||
"yes".fg(theme.secondary),
|
||||
" N / Esc ".fg(theme.foreground).bold(),
|
||||
"cancel".fg(theme.secondary),
|
||||
]),
|
||||
]))
|
||||
.alignment(Alignment::Center)
|
||||
.wrap(Wrap { trim: true })
|
||||
.block(
|
||||
Block::bordered()
|
||||
.title(" Confirm quit ".fg(theme.warning).bold())
|
||||
.border_set(border::DOUBLE)
|
||||
.border_style(Style::default().fg(theme.warning))
|
||||
.style(Style::default().bg(theme.background)),
|
||||
)
|
||||
.render(popup, buf);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1459,11 +1500,37 @@ mod tests {
|
|||
}
|
||||
|
||||
#[test]
|
||||
fn selection_clamps_and_quit_requests_exit() {
|
||||
fn quit_requires_confirmation_and_escape_does_not_quit() {
|
||||
let mut app = LiveTui::new(DemoClient::default()).unwrap();
|
||||
app.handle_key_event(press(KeyCode::Down));
|
||||
assert_eq!(app.selected, 0);
|
||||
|
||||
app.handle_key_event(press(KeyCode::Esc));
|
||||
assert!(!app.exit);
|
||||
|
||||
app.handle_key_event(press(KeyCode::Char('q')));
|
||||
assert!(!app.exit);
|
||||
let area = Rect::new(0, 0, 80, 20);
|
||||
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("Quit fader_master?"));
|
||||
|
||||
app.handle_key_event(press(KeyCode::Esc));
|
||||
app.handle_key_event(press(KeyCode::Char('y')));
|
||||
assert!(!app.exit);
|
||||
|
||||
app.handle_key_event(press(KeyCode::Char('q')));
|
||||
app.handle_key_event(press(KeyCode::Char('n')));
|
||||
app.handle_key_event(press(KeyCode::Char('y')));
|
||||
assert!(!app.exit);
|
||||
|
||||
app.handle_key_event(press(KeyCode::Char('q')));
|
||||
app.handle_key_event(press(KeyCode::Char('y')));
|
||||
assert!(app.exit);
|
||||
}
|
||||
|
||||
|
|
@ -1566,7 +1633,8 @@ mod tests {
|
|||
assert!(rendered.contains("65%"));
|
||||
assert!(rendered.contains("pickup: waiting"));
|
||||
assert!(rendered.contains("APC MINI: missing — connect device"));
|
||||
assert!(rendered.contains("Q/Esc"));
|
||||
assert!(rendered.contains(" Q "));
|
||||
assert!(!rendered.contains("Q/Esc"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
|
|||
Loading…
Reference in New Issue