| 1 | use crate::app::{App, AppResult}; |
| 2 | use crossterm::event::{KeyCode, KeyEvent, KeyModifiers}; |
| 3 | |
| 4 | pub fn handle_key_events(key_event: KeyEvent, app: &mut App) -> AppResult<()> { |
| 5 | match key_event.code { |
| 6 | KeyCode::Char('q') | KeyCode::Esc => app.quit(), |
| 7 | KeyCode::Char('c') | KeyCode::Char('C') => { |
| 8 | if key_event.modifiers == KeyModifiers::CONTROL { |
| 9 | app.quit(); |
| 10 | } |
| 11 | } |
| 12 | |
| 13 | KeyCode::Char('j') => { |
| 14 | app.list.next(); |
| 15 | } |
| 16 | |
| 17 | KeyCode::Char('k') => { |
| 18 | app.list.prev(); |
| 19 | } |
| 20 | |
| 21 | KeyCode::Enter | KeyCode::Char('l') => { |
| 22 | let song = app.conn.get_song_with_only_filename(app.conn.songs_filenames.get(app.list.index).unwrap()); |
| 23 | app.conn.push(&song).unwrap(); |
| 24 | app.update_queue(); |
| 25 | } |
| 26 | |
| 27 | // Playback controls |
| 28 | // Toggle Pause |
| 29 | KeyCode::Char('p') => { |
| 30 | app.conn.toggle_pause(); |
| 31 | } |
| 32 | |
| 33 | // Pause |
| 34 | KeyCode::Char('s') => { |
| 35 | app.conn.pause(); |
| 36 | } |
| 37 | |
| 38 | // Clearn Queue |
| 39 | KeyCode::Char('x') => { |
| 40 | app.conn.conn.clear()?; |
| 41 | app.update_queue(); |
| 42 | } |
| 43 | _ => {} |
| 44 | } |
| 45 | |
| 46 | Ok(()) |
| 47 | } |