Krolyxon
Commit 83c86d3

rmptui83c86d3

fix keys being registerd in editing modes

Author
krolxon
Date
2024-05-09 12:22 +0530
Parent
1187e4f
Commit
83c86d3c2d6fa06f035ba5326809e4c7adf8edbe

+196 −194

1 file changed

  1. M src/event/handler.rs +196 −194
M src/event/handler.rs View
@@ -15,250 +15,252 @@ pub fn handle_key_events(key_event: KeyEvent, app: &mut App) -> AppResult<()> {
1515 pl_rename_keys::handle_pl_rename_keys(key_event, app)?;
1616 } else if app.playlist_popup {
1717 pl_append_keys::hande_pl_append_keys(key_event, app)?;
18− }
19−
20− // General KeyMaps
21− match key_event.code {
22− // Quit
23− KeyCode::Char('q') => app.quit(),
24− KeyCode::Char('c') | KeyCode::Char('C') => {
25− if key_event.modifiers == KeyModifiers::CONTROL {
26− app.quit();
27− } else {
28− app.conn.conn.clear()?;
29− app.conn.update_status();
30− app.queue_list.list.clear();
31− app.queue_list.reset_index();
18+ } else {
19+ // General KeyMaps
20+ match key_event.code {
21+ // Quit
22+ KeyCode::Char('q') => app.quit(),
23+ KeyCode::Char('c') | KeyCode::Char('C') => {
24+ if key_event.modifiers == KeyModifiers::CONTROL {
25+ app.quit();
26+ } else {
27+ app.conn.conn.clear()?;
28+ app.conn.update_status();
29+ app.queue_list.list.clear();
30+ app.queue_list.reset_index();
31+ }
3232 }
33− }
3433
35− // Playback controls
36− // Toggle Pause
37− KeyCode::Char('p') => app.conn.toggle_pause(),
34+ // Playback controls
35+ // Toggle Pause
36+ KeyCode::Char('p') => app.conn.toggle_pause(),
3837
39− // Pause
40− KeyCode::Char('s') => app.conn.pause(),
38+ // Pause
39+ KeyCode::Char('s') => app.conn.pause(),
4140
42− // Toggle rpeat
43− KeyCode::Char('r') => {
44− app.conn.toggle_repeat();
45− app.conn.update_status();
46− }
41+ // Toggle rpeat
42+ KeyCode::Char('r') => {
43+ app.conn.toggle_repeat();
44+ app.conn.update_status();
45+ }
4746
48− // Toggle random
49− KeyCode::Char('z') => {
50− app.conn.toggle_random();
51− app.conn.update_status();
52− }
47+ // Toggle random
48+ KeyCode::Char('z') => {
49+ app.conn.toggle_random();
50+ app.conn.update_status();
51+ }
5352
54− // Dmenu prompt
55− KeyCode::Char('D') => app.conn.play_dmenu()?,
53+ // Dmenu prompt
54+ KeyCode::Char('D') => app.conn.play_dmenu()?,
5655
57− // add to queue
58− KeyCode::Char('a') => app.playlist_popup = true,
56+ // add to queue
57+ KeyCode::Char('a') => app.playlist_popup = true,
5958
60− // Fast forward
61− KeyCode::Char('f') => {
62− let place = app.conn.conn.status().unwrap().song.unwrap().pos;
63− let (pos, _) = app.conn.conn.status().unwrap().time.unwrap();
64− let pos = Duration::from_secs(pos.as_secs().wrapping_add(2));
65− app.conn.conn.seek(place, pos)?;
66− }
59+ // Fast forward
60+ KeyCode::Char('f') => {
61+ let place = app.conn.conn.status().unwrap().song.unwrap().pos;
62+ let (pos, _) = app.conn.conn.status().unwrap().time.unwrap();
63+ let pos = Duration::from_secs(pos.as_secs().wrapping_add(2));
64+ app.conn.conn.seek(place, pos)?;
65+ }
6766
68− // backward
69− KeyCode::Char('b') => {
70− let place = app.conn.conn.status().unwrap().song.unwrap().pos;
71− let (pos, _) = app.conn.conn.status().unwrap().time.unwrap();
72− let pos = Duration::from_secs(pos.as_secs().wrapping_add(2));
73− app.conn.conn.seek(place, pos)?;
74− }
67+ // backward
68+ KeyCode::Char('b') => {
69+ let place = app.conn.conn.status().unwrap().song.unwrap().pos;
70+ let (pos, _) = app.conn.conn.status().unwrap().time.unwrap();
71+ let pos = Duration::from_secs(pos.as_secs().wrapping_add(2));
72+ app.conn.conn.seek(place, pos)?;
73+ }
7574
76− // Cycle through tabs
77− KeyCode::Tab => {
78− app.cycle_tabls();
79− }
75+ // Cycle through tabs
76+ KeyCode::Tab => {
77+ app.cycle_tabls();
78+ }
8079
81− // Directory browser tab
82− KeyCode::Char('1') => {
83− app.selected_tab = SelectedTab::Queue;
84− }
80+ // Directory browser tab
81+ KeyCode::Char('1') => {
82+ app.selected_tab = SelectedTab::Queue;
83+ }
8584
86− // Playing queue tab
87− KeyCode::Char('2') => {
88− app.selected_tab = SelectedTab::DirectoryBrowser;
89− }
85+ // Playing queue tab
86+ KeyCode::Char('2') => {
87+ app.selected_tab = SelectedTab::DirectoryBrowser;
88+ }
9089
91− // Playlists tab
92− KeyCode::Char('3') => {
93− app.selected_tab = SelectedTab::Playlists;
94− }
90+ // Playlists tab
91+ KeyCode::Char('3') => {
92+ app.selected_tab = SelectedTab::Playlists;
93+ }
9594
96− // Play next song
97− KeyCode::Char('>') => {
98− if !app.queue_list.list.is_empty() {
99− app.conn.conn.next()?;
100− app.update_queue();
95+ // Play next song
96+ KeyCode::Char('>') => {
97+ if !app.queue_list.list.is_empty() {
98+ app.conn.conn.next()?;
99+ app.update_queue();
100+ }
101101 }
102− }
103102
104− // Play previous song
105− KeyCode::Char('<') => {
106− if !app.queue_list.list.is_empty() {
107− app.conn.conn.prev()?;
108− app.update_queue();
103+ // Play previous song
104+ KeyCode::Char('<') => {
105+ if !app.queue_list.list.is_empty() {
106+ app.conn.conn.prev()?;
107+ app.update_queue();
108+ }
109109 }
110− }
111110
112− // Volume controls
113− KeyCode::Char('=') => {
114− app.conn.inc_volume(2);
115− app.conn.update_status();
116− }
111+ // Volume controls
112+ KeyCode::Char('=') => {
113+ app.conn.inc_volume(2);
114+ app.conn.update_status();
115+ }
117116
118− KeyCode::Char('-') => {
119− app.conn.dec_volume(2);
120− app.conn.update_status();
121− }
117+ KeyCode::Char('-') => {
118+ app.conn.dec_volume(2);
119+ app.conn.update_status();
120+ }
122121
123− // Update MPD database
124− KeyCode::Char('U') => {
125− app.conn.conn.rescan()?;
126− app.browser.update_directory(&mut app.conn)?;
127− }
122+ // Update MPD database
123+ KeyCode::Char('U') => {
124+ app.conn.conn.rescan()?;
125+ app.browser.update_directory(&mut app.conn)?;
126+ }
128127
129− // Search for songs
130− KeyCode::Char('/') => {
131− if app.inputmode == InputMode::Normal {
132− app.inputmode = InputMode::Editing;
133− } else {
134− app.inputmode = InputMode::Normal;
128+ // Search for songs
129+ KeyCode::Char('/') => {
130+ if app.inputmode == InputMode::Normal {
131+ app.inputmode = InputMode::Editing;
132+ } else {
133+ app.inputmode = InputMode::Normal;
134+ }
135135 }
136− }
137136
138− // Add or Remove from Current Playlist
139− KeyCode::Char(' ') | KeyCode::Backspace => {
140− app.handle_add_or_remove_from_current_playlist()?;
137+ // Add or Remove from Current Playlist
138+ KeyCode::Char(' ') | KeyCode::Backspace => {
139+ app.handle_add_or_remove_from_current_playlist()?;
140+ }
141+ _ => {}
141142 }
142− _ => {}
143− }
144−
145− // Tab specific keymaps
146− match app.selected_tab {
147− SelectedTab::Queue => {
148− match key_event.code {
149− // Go Up
150− KeyCode::Char('j') | KeyCode::Down => app.queue_list.next(),
151143
152− // Go down
153− KeyCode::Char('k') | KeyCode::Up => app.queue_list.prev(),
144+ // Tab specific keymaps
145+ match app.selected_tab {
146+ SelectedTab::Queue => {
147+ match key_event.code {
148+ // Go Up
149+ KeyCode::Char('j') | KeyCode::Down => app.queue_list.next(),
154150
155− // Next directory
156− KeyCode::Enter | KeyCode::Char('l') | KeyCode::Right => {
157− app.conn.conn.switch(app.queue_list.index as u32)?;
158− app.conn.update_status();
159− }
151+ // Go down
152+ KeyCode::Char('k') | KeyCode::Up => app.queue_list.prev(),
160153
161− // Delete highlighted song from the queue
162− KeyCode::Char('d') => {
163− if app.queue_list.index >= app.queue_list.list.len() - 1
164− && app.queue_list.index != 0
165− {
166− app.queue_list.index -= 1;
154+ // Next directory
155+ KeyCode::Enter | KeyCode::Char('l') | KeyCode::Right => {
156+ app.conn.conn.switch(app.queue_list.index as u32)?;
157+ app.conn.update_status();
167158 }
168159
169− app.conn.conn.delete(app.queue_list.index as u32)?;
170− app.update_queue();
171− }
160+ // Delete highlighted song from the queue
161+ KeyCode::Char('d') => {
162+ if app.queue_list.index >= app.queue_list.list.len() - 1
163+ && app.queue_list.index != 0
164+ {
165+ app.queue_list.index -= 1;
166+ }
172167
173− // Swap highlighted song with next one
174− KeyCode::Char('J') => {
175− let current: u32 = app.queue_list.index as u32;
176− let next: u32 = if (current + 1) as usize == app.queue_list.list.len() {
177− app.queue_list.index as u32
178− } else {
179− app.queue_list.index += 1;
180− current + 1
181− };
182− app.conn.conn.swap(current, next)?;
183− app.update_queue();
184− }
168+ app.conn.conn.delete(app.queue_list.index as u32)?;
169+ app.update_queue();
170+ }
185171
186− // Swap highlighted song with previous one
187− KeyCode::Char('K') => {
188− let current: u32 = app.queue_list.index as u32;
189− let prev: u32 = if current == 0 {
190− app.queue_list.index as u32
191− } else {
192− app.queue_list.index -= 1;
193− current - 1
194− };
195− app.conn.conn.swap(current, prev)?;
196− app.update_queue();
197− }
172+ // Swap highlighted song with next one
173+ KeyCode::Char('J') => {
174+ let current: u32 = app.queue_list.index as u32;
175+ let next: u32 = if (current + 1) as usize == app.queue_list.list.len() {
176+ app.queue_list.index as u32
177+ } else {
178+ app.queue_list.index += 1;
179+ current + 1
180+ };
181+ app.conn.conn.swap(current, next)?;
182+ app.update_queue();
183+ }
198184
199− // go to top of list
200− KeyCode::Char('g') => app.queue_list.index = 0,
185+ // Swap highlighted song with previous one
186+ KeyCode::Char('K') => {
187+ let current: u32 = app.queue_list.index as u32;
188+ let prev: u32 = if current == 0 {
189+ app.queue_list.index as u32
190+ } else {
191+ app.queue_list.index -= 1;
192+ current - 1
193+ };
194+ app.conn.conn.swap(current, prev)?;
195+ app.update_queue();
196+ }
197+
198+ // go to top of list
199+ KeyCode::Char('g') => app.queue_list.index = 0,
201200
202− // go to bottom of list
203− KeyCode::Char('G') => app.queue_list.index = app.queue_list.list.len() - 1,
201+ // go to bottom of list
202+ KeyCode::Char('G') => app.queue_list.index = app.queue_list.list.len() - 1,
204203
205− _ => {}
204+ _ => {}
205+ }
206206 }
207− }
208207
209− SelectedTab::DirectoryBrowser => {
210− match key_event.code {
211− // Go Up
212− KeyCode::Char('j') | KeyCode::Down => app.browser.next(),
208+ SelectedTab::DirectoryBrowser => {
209+ match key_event.code {
210+ // Go Up
211+ KeyCode::Char('j') | KeyCode::Down => app.browser.next(),
213212
214− // Go down
215− KeyCode::Char('k') | KeyCode::Up => app.browser.prev(),
213+ // Go down
214+ KeyCode::Char('k') | KeyCode::Up => app.browser.prev(),
216215
217− // Next directory
218− KeyCode::Enter | KeyCode::Char('l') | KeyCode::Right => {
219− // app.update_queue();
220− app.handle_enter()?;
221− app.conn.update_status();
222− }
216+ // Next directory
217+ KeyCode::Enter | KeyCode::Char('l') | KeyCode::Right => {
218+ // app.update_queue();
219+ app.handle_enter()?;
220+ app.conn.update_status();
221+ }
223222
224− // head back to previous directory
225− KeyCode::Char('h') | KeyCode::Left => app.browser.handle_go_back(&mut app.conn)?,
223+ // head back to previous directory
224+ KeyCode::Char('h') | KeyCode::Left => {
225+ app.browser.handle_go_back(&mut app.conn)?
226+ }
226227
227− // go to top of list
228− KeyCode::Char('g') => app.browser.selected = 0,
228+ // go to top of list
229+ KeyCode::Char('g') => app.browser.selected = 0,
229230
230− // go to bottom of list
231− KeyCode::Char('G') => app.browser.selected = app.browser.filetree.len() - 1,
231+ // go to bottom of list
232+ KeyCode::Char('G') => app.browser.selected = app.browser.filetree.len() - 1,
232233
233− _ => {}
234+ _ => {}
235+ }
234236 }
235− }
236237
237− SelectedTab::Playlists => {
238− match key_event.code {
239− // Go Up
240− KeyCode::Char('j') | KeyCode::Down => app.pl_list.next(),
238+ SelectedTab::Playlists => {
239+ match key_event.code {
240+ // Go Up
241+ KeyCode::Char('j') | KeyCode::Down => app.pl_list.next(),
241242
242− // Go down
243− KeyCode::Char('k') | KeyCode::Up => app.pl_list.prev(),
243+ // Go down
244+ KeyCode::Char('k') | KeyCode::Up => app.pl_list.prev(),
244245
245− // go to top of list
246− KeyCode::Char('g') => app.pl_list.index = 0,
246+ // go to top of list
247+ KeyCode::Char('g') => app.pl_list.index = 0,
247248
248− // go to bottom of list
249− KeyCode::Char('G') => app.pl_list.index = app.pl_list.list.len() - 1,
249+ // go to bottom of list
250+ KeyCode::Char('G') => app.pl_list.index = app.pl_list.list.len() - 1,
250251
251− // Change playlist name
252− KeyCode::Char('e') => app.change_playlist_name()?,
252+ // Change playlist name
253+ KeyCode::Char('e') => app.change_playlist_name()?,
253254
254− // add to current playlist
255− KeyCode::Enter | KeyCode::Char('l') | KeyCode::Right | KeyCode::Char(' ') => {
256− // app.update_queue();
257− app.conn
258− .load_playlist(app.pl_list.list.get(app.pl_list.index).unwrap())?;
259− app.conn.update_status();
255+ // add to current playlist
256+ KeyCode::Enter | KeyCode::Char('l') | KeyCode::Right | KeyCode::Char(' ') => {
257+ // app.update_queue();
258+ app.conn
259+ .load_playlist(app.pl_list.list.get(app.pl_list.index).unwrap())?;
260+ app.conn.update_status();
261+ }
262+ _ => {}
260263 }
261− _ => {}
262264 }
263265 }
264266 }