Krolyxon
Commit 05c4b17

rmptuisrchandler.rs

79 lines · 2.1 KB · Rust

1use crate::app::{App, AppResult};
2use crossterm::event::{KeyCode, KeyEvent, KeyModifiers};
3
4pub 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.song_list.next();
15 }
16
17 KeyCode::Char('k') => {
18 app.song_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.song_list.index).unwrap());
23 app.conn.push(&song)?;
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
39 // Clearn Queue
40 KeyCode::Char('x') => {
41 app.conn.conn.clear()?;
42 // app.update_queue();
43 }
44
45 KeyCode::Char('d') => {
46 app.conn.play_dmenu()?;
47 }
48
49 KeyCode::Down=> {
50 app.pl_list.next();
51 }
52
53 KeyCode::Up=> {
54 app.pl_list.prev();
55 }
56
57
58 KeyCode::Right => {
59 app.conn.push_playlist(app.pl_list.list.get(app.pl_list.index).unwrap())?;
60 }
61
62 KeyCode::Char('f')=> {
63 // let place = app.conn.conn.status().unwrap().duration;
64 let (pos, _) = app.conn.conn.status().unwrap().time.unwrap();
65 let pos: i64 = (pos.as_secs() + 2).try_into().unwrap();
66 app.conn.conn.seek(2, pos )?;
67 }
68
69 KeyCode::Char('b')=> {
70 // let place = app.conn.conn.status().unwrap().duration;
71 let (pos, _) = app.conn.conn.status().unwrap().time.unwrap();
72 let pos: i64 = (pos.as_secs() - 2).try_into().unwrap();
73 app.conn.conn.seek(2, pos )?;
74 }
75 _ => {}
76 }
77
78 Ok(())
79}