Krolyxon
Commit 044101b

rmptuisrchandler.rs

90 lines · 2.5 KB · Rust

1use std::time::Duration;
2
3use crate::app::{App, AppResult};
4use crossterm::event::{KeyCode, KeyEvent, KeyModifiers};
5
6pub fn handle_key_events(key_event: KeyEvent, app: &mut App) -> AppResult<()> {
7 match key_event.code {
8 KeyCode::Char('q') | KeyCode::Esc => app.quit(),
9 KeyCode::Char('c') | KeyCode::Char('C') => {
10 if key_event.modifiers == KeyModifiers::CONTROL {
11 app.quit();
12 }
13 }
14
15 KeyCode::Char('j') => {
16 app.song_list.next();
17 }
18
19 KeyCode::Char('k') => {
20 app.song_list.prev();
21 }
22
23 KeyCode::Enter | KeyCode::Char('l') => {
24 let song = app.conn.get_song_with_only_filename(
25 app.conn.songs_filenames.get(app.song_list.index).unwrap(),
26 );
27 app.conn.push(&song)?;
28 // app.update_queue();
29 }
30
31 // Playback controls
32 // Toggle Pause
33 KeyCode::Char('p') => {
34 app.conn.toggle_pause();
35 }
36
37 // Pause
38 KeyCode::Char('s') => {
39 app.conn.pause();
40 }
41
42 // Clearn Queue
43 KeyCode::Char('x') => {
44 app.conn.conn.clear()?;
45 // app.update_queue();
46 }
47
48 KeyCode::Char('d') => {
49 app.conn.play_dmenu()?;
50 }
51
52 KeyCode::Down => {
53 if key_event.modifiers == KeyModifiers::SHIFT {
54 app.queue_list.next();
55 } else {
56 app.pl_list.next();
57 }
58 }
59
60 KeyCode::Up => {
61 if key_event.modifiers == KeyModifiers::SHIFT {
62 app.queue_list.prev();
63 } else {
64 app.pl_list.prev();
65 }
66 }
67
68 KeyCode::Right => {
69 app.conn
70 .push_playlist(app.pl_list.list.get(app.pl_list.index).unwrap())?;
71 }
72
73 KeyCode::Char('f') => {
74 let place = app.conn.conn.status().unwrap().song.unwrap().pos;
75 let (pos, _) = app.conn.conn.status().unwrap().time.unwrap();
76 let pos = Duration::from_secs(pos.as_secs().wrapping_add(2));
77 app.conn.conn.seek(place, pos)?;
78 }
79
80 KeyCode::Char('b') => {
81 let place = app.conn.conn.status().unwrap().song.unwrap().pos;
82 let (pos, _) = app.conn.conn.status().unwrap().time.unwrap();
83 let pos = Duration::from_secs(pos.as_secs().wrapping_add(2));
84 app.conn.conn.seek(place, pos)?;
85 }
86 _ => {}
87 }
88
89 Ok(())
90}