1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
|
use std::time::Duration;
use crate::app::{App, AppResult, SelectedTab};
use crossterm::event::{KeyCode, KeyEvent, KeyModifiers};
use ratatui::style::Modifier;
pub fn handle_key_events(key_event: KeyEvent, app: &mut App) -> AppResult<()> {
match key_event.code {
KeyCode::Char('q') | KeyCode::Esc => app.quit(),
KeyCode::Char('c') | KeyCode::Char('C') => {
if key_event.modifiers == KeyModifiers::CONTROL {
app.quit();
}
}
KeyCode::Char('j') | KeyCode::Down => match app.selected_tab {
SelectedTab::SongList => app.song_list.next(),
SelectedTab::Queue => app.queue_list.next(),
SelectedTab::Playlists => app.pl_list.next(),
},
KeyCode::Char('k') | KeyCode::Up => match app.selected_tab {
SelectedTab::SongList => app.song_list.prev(),
SelectedTab::Queue => app.queue_list.prev(),
SelectedTab::Playlists => app.pl_list.prev(),
},
KeyCode::Enter | KeyCode::Char('l') => {
// app.update_queue();
match app.selected_tab {
SelectedTab::SongList => {
let song = app.conn.get_song_with_only_filename(
app.conn.songs_filenames.get(app.song_list.index).unwrap(),
);
app.conn.push(&song)?;
}
SelectedTab::Queue => {}
SelectedTab::Playlists => {
app.conn
.push_playlist(app.pl_list.list.get(app.pl_list.index).unwrap())?;
}
}
}
// Playback controls
// Toggle Pause
KeyCode::Char('p') => {
app.conn.toggle_pause();
app.conn.update_state();
}
// Pause
KeyCode::Char('s') => {
app.conn.pause();
app.conn.update_state();
}
// Clear Queue
KeyCode::Char('x') => {
app.conn.conn.clear()?;
app.conn.update_state();
// app.update_queue();
}
KeyCode::Char('d') => {
app.conn.play_dmenu()?;
}
KeyCode::Right => {
app.conn
.push_playlist(app.pl_list.list.get(app.pl_list.index).unwrap())?;
}
KeyCode::Char('f') => {
let place = app.conn.conn.status().unwrap().song.unwrap().pos;
let (pos, _) = app.conn.conn.status().unwrap().time.unwrap();
let pos = Duration::from_secs(pos.as_secs().wrapping_add(2));
app.conn.conn.seek(place, pos)?;
}
KeyCode::Char('b') => {
let place = app.conn.conn.status().unwrap().song.unwrap().pos;
let (pos, _) = app.conn.conn.status().unwrap().time.unwrap();
let pos = Duration::from_secs(pos.as_secs().wrapping_add(2));
app.conn.conn.seek(place, pos)?;
}
KeyCode::Tab => {
app.cycle_tabls();
}
KeyCode::Char('1') => {
app.selected_tab = SelectedTab::SongList;
}
KeyCode::Char('2') => {
app.selected_tab = SelectedTab::Queue;
}
KeyCode::Char('3') => {
app.selected_tab = SelectedTab::Playlists;
}
KeyCode::Char('n') => {
app.conn.conn.next()?;
}
KeyCode::Char('N') => {
app.conn.conn.prev()?;
}
// Volume controls
KeyCode::Char('=') => {
app.conn.inc_volume(2);
}
KeyCode::Char('-') => {
app.conn.dec_volume(2);
}
_ => {}
}
Ok(())
}
|