1use crossterm::event::{KeyCode, KeyEvent, KeyModifiers};
2
3#[derive(Debug, Clone, PartialEq)]
4pub enum Action {
5 SelectNext,
6 SelectPrev,
7 Restart,
8 Stop,
9 StopAll,
10 CycleStream,
11 TogglePause,
12 Quit,
13 QuitAndStop,
14 None,
15}
16
17pub fn handle_key(key: KeyEvent) -> Action {
18 match key.code {
19 KeyCode::Down | KeyCode::Char('j') => Action::SelectNext,
20 KeyCode::Up | KeyCode::Char('k') => Action::SelectPrev,
21 KeyCode::Char('r') => Action::Restart,
22 KeyCode::Char('x') => Action::Stop,
23 KeyCode::Char('X') => Action::StopAll,
24 KeyCode::Char('e') => Action::CycleStream,
25 KeyCode::Char(' ') => Action::TogglePause,
26 KeyCode::Char('q') => Action::Quit,
27 KeyCode::Char('Q') => Action::QuitAndStop,
28 KeyCode::Char('c') if key.modifiers.contains(KeyModifiers::CONTROL) => Action::Quit,
29 _ => Action::None,
30 }
31}