rmptuicef5f73
general and tab specific keys seperated
+205 −186
1 file changed
- M src/event/handler.rs +205 −186
| @@ -8,239 +8,258 @@ use std::time::Duration; | |||
| 8 | 8 | use super::{pl_append_keys, pl_rename_keys, search_keys}; | |
| 9 | 9 | ||
| 10 | 10 | pub fn handle_key_events(key_event: KeyEvent, app: &mut App) -> AppResult<()> { | |
| 11 | − | // Live search update | |
| 11 | + | // searching, playlist renaming, playlist appending | |
| 12 | 12 | if app.inputmode == InputMode::Editing { | |
| 13 | 13 | search_keys::handle_search_keys(key_event, app)?; | |
| 14 | 14 | } else if app.inputmode == InputMode::PlaylistRename { | |
| 15 | 15 | pl_rename_keys::handle_pl_rename_keys(key_event, app)?; | |
| 16 | 16 | } else if app.playlist_popup { | |
| 17 | 17 | pl_append_keys::hande_pl_append_keys(key_event, app)?; | |
| 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 | − | } | |
| 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(); | |
| 32 | 32 | } | |
| 33 | + | } | |
| 33 | 34 | ||
| 34 | − | // Go Up | |
| 35 | − | KeyCode::Char('j') | KeyCode::Down => match app.selected_tab { | |
| 36 | − | SelectedTab::DirectoryBrowser => app.browser.next(), | |
| 37 | − | SelectedTab::Queue => app.queue_list.next(), | |
| 38 | − | SelectedTab::Playlists => app.pl_list.next(), | |
| 39 | − | }, | |
| 40 | − | ||
| 41 | − | // Go down | |
| 42 | − | KeyCode::Char('k') | KeyCode::Up => match app.selected_tab { | |
| 43 | − | SelectedTab::DirectoryBrowser => app.browser.prev(), | |
| 44 | − | SelectedTab::Queue => app.queue_list.prev(), | |
| 45 | − | SelectedTab::Playlists => app.pl_list.prev(), | |
| 46 | − | }, | |
| 47 | − | ||
| 48 | − | // Next directory | |
| 49 | − | KeyCode::Enter | KeyCode::Char('l') | KeyCode::Right => { | |
| 50 | − | // app.update_queue(); | |
| 51 | − | ||
| 52 | − | match app.selected_tab { | |
| 53 | − | SelectedTab::DirectoryBrowser => { | |
| 54 | − | app.handle_enter()?; | |
| 55 | − | } | |
| 35 | + | // Playback controls | |
| 36 | + | // Toggle Pause | |
| 37 | + | KeyCode::Char('p') => app.conn.toggle_pause(), | |
| 56 | 38 | ||
| 57 | − | SelectedTab::Queue => { | |
| 58 | − | app.conn.conn.switch(app.queue_list.index as u32)?; | |
| 59 | − | } | |
| 39 | + | // Pause | |
| 40 | + | KeyCode::Char('s') => app.conn.pause(), | |
| 60 | 41 | ||
| 61 | − | SelectedTab::Playlists => { | |
| 62 | − | app.conn | |
| 63 | − | .load_playlist(app.pl_list.list.get(app.pl_list.index).unwrap())?; | |
| 64 | − | } | |
| 65 | − | } | |
| 66 | − | app.conn.update_status(); | |
| 67 | − | } | |
| 42 | + | // Toggle rpeat | |
| 43 | + | KeyCode::Char('r') => { | |
| 44 | + | app.conn.toggle_repeat(); | |
| 45 | + | app.conn.update_status(); | |
| 46 | + | } | |
| 68 | 47 | ||
| 69 | − | // head back to previous directory | |
| 70 | − | KeyCode::Char('h') | KeyCode::Left => match app.selected_tab { | |
| 71 | − | SelectedTab::DirectoryBrowser => { | |
| 72 | − | app.browser.handle_go_back(&mut app.conn)?; | |
| 73 | − | } | |
| 74 | − | SelectedTab::Queue => {} | |
| 75 | − | SelectedTab::Playlists => {} | |
| 76 | − | }, | |
| 48 | + | // Toggle random | |
| 49 | + | KeyCode::Char('z') => { | |
| 50 | + | app.conn.toggle_random(); | |
| 51 | + | app.conn.update_status(); | |
| 52 | + | } | |
| 77 | 53 | ||
| 78 | − | // Playback controls | |
| 79 | − | // Toggle Pause | |
| 80 | − | KeyCode::Char('p') => app.conn.toggle_pause(), | |
| 54 | + | // Dmenu prompt | |
| 55 | + | KeyCode::Char('D') => app.conn.play_dmenu()?, | |
| 81 | 56 | ||
| 82 | − | // Pause | |
| 83 | − | KeyCode::Char('s') => app.conn.pause(), | |
| 57 | + | // add to queue | |
| 58 | + | KeyCode::Char('a') => app.playlist_popup = true, | |
| 84 | 59 | ||
| 85 | − | // Toggle rpeat | |
| 86 | − | KeyCode::Char('r') => { | |
| 87 | − | app.conn.toggle_repeat(); | |
| 88 | − | app.conn.update_status(); | |
| 89 | − | } | |
| 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 | + | } | |
| 90 | 67 | ||
| 91 | − | // Toggle random | |
| 92 | − | KeyCode::Char('z') => { | |
| 93 | − | app.conn.toggle_random(); | |
| 94 | − | app.conn.update_status(); | |
| 95 | − | } | |
| 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 | + | } | |
| 96 | 75 | ||
| 97 | − | // Dmenu prompt | |
| 98 | − | KeyCode::Char('D') => app.conn.play_dmenu()?, | |
| 76 | + | // Cycle through tabs | |
| 77 | + | KeyCode::Tab => { | |
| 78 | + | app.cycle_tabls(); | |
| 79 | + | } | |
| 99 | 80 | ||
| 100 | − | // add to queue | |
| 101 | − | KeyCode::Char('a') => app.playlist_popup = true, | |
| 81 | + | // Directory browser tab | |
| 82 | + | KeyCode::Char('1') => { | |
| 83 | + | app.selected_tab = SelectedTab::Queue; | |
| 84 | + | } | |
| 102 | 85 | ||
| 103 | − | // Fast forward | |
| 104 | − | KeyCode::Char('f') => { | |
| 105 | − | let place = app.conn.conn.status().unwrap().song.unwrap().pos; | |
| 106 | − | let (pos, _) = app.conn.conn.status().unwrap().time.unwrap(); | |
| 107 | − | let pos = Duration::from_secs(pos.as_secs().wrapping_add(2)); | |
| 108 | − | app.conn.conn.seek(place, pos)?; | |
| 109 | − | } | |
| 86 | + | // Playing queue tab | |
| 87 | + | KeyCode::Char('2') => { | |
| 88 | + | app.selected_tab = SelectedTab::DirectoryBrowser; | |
| 89 | + | } | |
| 110 | 90 | ||
| 111 | − | // backward | |
| 112 | − | KeyCode::Char('b') => { | |
| 113 | − | let place = app.conn.conn.status().unwrap().song.unwrap().pos; | |
| 114 | − | let (pos, _) = app.conn.conn.status().unwrap().time.unwrap(); | |
| 115 | − | let pos = Duration::from_secs(pos.as_secs().wrapping_add(2)); | |
| 116 | − | app.conn.conn.seek(place, pos)?; | |
| 117 | − | } | |
| 91 | + | // Playlists tab | |
| 92 | + | KeyCode::Char('3') => { | |
| 93 | + | app.selected_tab = SelectedTab::Playlists; | |
| 94 | + | } | |
| 118 | 95 | ||
| 119 | − | // Cycle through tabs | |
| 120 | − | KeyCode::Tab => { | |
| 121 | − | app.cycle_tabls(); | |
| 96 | + | // Play next song | |
| 97 | + | KeyCode::Char('>') => { | |
| 98 | + | if !app.queue_list.list.is_empty() { | |
| 99 | + | app.conn.conn.next()?; | |
| 100 | + | app.update_queue(); | |
| 122 | 101 | } | |
| 102 | + | } | |
| 123 | 103 | ||
| 124 | − | // Directory browser tab | |
| 125 | − | KeyCode::Char('1') => { | |
| 126 | − | app.selected_tab = SelectedTab::Queue; | |
| 104 | + | // Play previous song | |
| 105 | + | KeyCode::Char('<') => { | |
| 106 | + | if !app.queue_list.list.is_empty() { | |
| 107 | + | app.conn.conn.prev()?; | |
| 108 | + | app.update_queue(); | |
| 127 | 109 | } | |
| 110 | + | } | |
| 128 | 111 | ||
| 129 | − | // Playing queue tab | |
| 130 | − | KeyCode::Char('2') => { | |
| 131 | − | app.selected_tab = SelectedTab::DirectoryBrowser; | |
| 132 | − | } | |
| 112 | + | // Volume controls | |
| 113 | + | KeyCode::Char('=') => { | |
| 114 | + | app.conn.inc_volume(2); | |
| 115 | + | app.conn.update_status(); | |
| 116 | + | } | |
| 133 | 117 | ||
| 134 | − | // Playlists tab | |
| 135 | − | KeyCode::Char('3') => { | |
| 136 | − | app.selected_tab = SelectedTab::Playlists; | |
| 118 | + | KeyCode::Char('-') => { | |
| 119 | + | app.conn.dec_volume(2); | |
| 120 | + | app.conn.update_status(); | |
| 121 | + | } | |
| 122 | + | ||
| 123 | + | // Update MPD database | |
| 124 | + | KeyCode::Char('U') => { | |
| 125 | + | app.conn.conn.rescan()?; | |
| 126 | + | app.browser.update_directory(&mut app.conn)?; | |
| 127 | + | } | |
| 128 | + | ||
| 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; | |
| 137 | 135 | } | |
| 136 | + | } | |
| 138 | 137 | ||
| 139 | − | // Play next song | |
| 140 | − | KeyCode::Char('>') => { | |
| 141 | − | if !app.queue_list.list.is_empty() { | |
| 142 | − | app.conn.conn.next()?; | |
| 138 | + | // Add or Remove from Current Playlist | |
| 139 | + | KeyCode::Char(' ') | KeyCode::Backspace => { | |
| 140 | + | app.handle_add_or_remove_from_current_playlist()?; | |
| 141 | + | } | |
| 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(), | |
| 151 | + | ||
| 152 | + | // Go down | |
| 153 | + | KeyCode::Char('k') | KeyCode::Up => app.queue_list.prev(), | |
| 154 | + | ||
| 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 | + | } | |
| 160 | + | ||
| 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; | |
| 167 | + | } | |
| 168 | + | ||
| 169 | + | app.conn.conn.delete(app.queue_list.index as u32)?; | |
| 143 | 170 | app.update_queue(); | |
| 144 | 171 | } | |
| 145 | − | } | |
| 146 | 172 | ||
| 147 | − | // Play previous song | |
| 148 | − | KeyCode::Char('<') => { | |
| 149 | − | if !app.queue_list.list.is_empty() { | |
| 150 | − | app.conn.conn.prev()?; | |
| 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) as u32 | |
| 181 | + | }; | |
| 182 | + | app.conn.conn.swap(current, next)?; | |
| 151 | 183 | app.update_queue(); | |
| 152 | 184 | } | |
| 153 | − | } | |
| 154 | 185 | ||
| 155 | − | // Volume controls | |
| 156 | − | KeyCode::Char('=') => { | |
| 157 | − | app.conn.inc_volume(2); | |
| 158 | − | app.conn.update_status(); | |
| 159 | − | } | |
| 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) as u32 | |
| 194 | + | }; | |
| 195 | + | app.conn.conn.swap(current, prev)?; | |
| 196 | + | app.update_queue(); | |
| 197 | + | } | |
| 160 | 198 | ||
| 161 | − | KeyCode::Char('-') => { | |
| 162 | − | app.conn.dec_volume(2); | |
| 163 | − | app.conn.update_status(); | |
| 199 | + | // go to top of list | |
| 200 | + | KeyCode::Char('g') => app.queue_list.index = 0, | |
| 201 | + | ||
| 202 | + | // go to bottom of list | |
| 203 | + | KeyCode::Char('G') => app.queue_list.index = app.queue_list.list.len() - 1, | |
| 204 | + | ||
| 205 | + | _ => {} | |
| 164 | 206 | } | |
| 207 | + | } | |
| 208 | + | ||
| 209 | + | SelectedTab::DirectoryBrowser => { | |
| 210 | + | match key_event.code { | |
| 211 | + | // Go Up | |
| 212 | + | KeyCode::Char('j') | KeyCode::Down => app.browser.next(), | |
| 213 | + | ||
| 214 | + | // Go down | |
| 215 | + | KeyCode::Char('k') | KeyCode::Up => app.browser.prev(), | |
| 165 | 216 | ||
| 166 | − | // Delete highlighted song from the queue | |
| 167 | − | KeyCode::Char('d') => { | |
| 168 | − | if app.queue_list.index >= app.queue_list.list.len() - 1 | |
| 169 | − | && app.queue_list.index != 0 | |
| 170 | − | { | |
| 171 | − | app.queue_list.index -= 1; | |
| 217 | + | // Next directory | |
| 218 | + | KeyCode::Enter | KeyCode::Char('l') | KeyCode::Right => { | |
| 219 | + | // app.update_queue(); | |
| 220 | + | app.handle_enter()?; | |
| 221 | + | app.conn.update_status(); | |
| 172 | 222 | } | |
| 173 | 223 | ||
| 174 | − | app.conn.conn.delete(app.queue_list.index as u32)?; | |
| 175 | − | app.update_queue(); | |
| 176 | − | } | |
| 224 | + | // head back to previous directory | |
| 225 | + | KeyCode::Char('h') | KeyCode::Left => app.browser.handle_go_back(&mut app.conn)?, | |
| 177 | 226 | ||
| 178 | − | // Swap highlighted song with next one | |
| 179 | − | KeyCode::Char('J') => { | |
| 180 | − | let current: u32 = app.queue_list.index as u32; | |
| 181 | − | let next: u32 = if (current + 1) as usize == app.queue_list.list.len() { | |
| 182 | − | app.queue_list.index as u32 | |
| 183 | − | } else { | |
| 184 | − | app.queue_list.index += 1; | |
| 185 | − | (current + 1) as u32 | |
| 186 | − | }; | |
| 187 | − | app.conn.conn.swap(current, next)?; | |
| 188 | − | app.update_queue(); | |
| 189 | − | } | |
| 227 | + | // go to top of list | |
| 228 | + | KeyCode::Char('g') => app.browser.selected = 0, | |
| 190 | 229 | ||
| 191 | − | // Swap highlighted song with previous one | |
| 192 | − | KeyCode::Char('K') => { | |
| 193 | − | let current: u32 = app.queue_list.index as u32; | |
| 194 | − | let prev: u32 = if current == 0 { | |
| 195 | − | app.queue_list.index as u32 | |
| 196 | − | } else { | |
| 197 | − | app.queue_list.index -= 1; | |
| 198 | − | (current - 1) as u32 | |
| 199 | − | }; | |
| 200 | − | app.conn.conn.swap(current, prev)?; | |
| 201 | − | app.update_queue(); | |
| 230 | + | // go to bottom of list | |
| 231 | + | KeyCode::Char('G') => app.browser.selected = app.browser.filetree.len() - 1, | |
| 232 | + | ||
| 233 | + | _ => {} | |
| 202 | 234 | } | |
| 235 | + | } | |
| 203 | 236 | ||
| 237 | + | SelectedTab::Playlists => { | |
| 238 | + | match key_event.code { | |
| 239 | + | // Go Up | |
| 240 | + | KeyCode::Char('j') | KeyCode::Down => app.pl_list.next(), | |
| 204 | 241 | ||
| 205 | − | // Update MPD database | |
| 206 | − | KeyCode::Char('U') => { | |
| 207 | − | app.conn.conn.rescan()?; | |
| 208 | − | app.browser.update_directory(&mut app.conn)?; | |
| 209 | − | } | |
| 242 | + | // Go down | |
| 243 | + | KeyCode::Char('k') | KeyCode::Up => app.pl_list.prev(), | |
| 210 | 244 | ||
| 211 | − | // Search for songs | |
| 212 | − | KeyCode::Char('/') => { | |
| 213 | − | if app.inputmode == InputMode::Normal { | |
| 214 | − | app.inputmode = InputMode::Editing; | |
| 215 | − | } else { | |
| 216 | − | app.inputmode = InputMode::Normal; | |
| 217 | − | } | |
| 218 | − | } | |
| 245 | + | // go to top of list | |
| 246 | + | KeyCode::Char('g') => app.pl_list.index = 0, | |
| 219 | 247 | ||
| 220 | − | // Remove from Current Playlsit | |
| 221 | − | KeyCode::Char(' ') | KeyCode::Backspace => { | |
| 222 | − | app.handle_add_or_remove_from_current_playlist()?; | |
| 223 | − | } | |
| 248 | + | // go to bottom of list | |
| 249 | + | KeyCode::Char('G') => app.pl_list.index = app.pl_list.list.len() - 1, | |
| 224 | 250 | ||
| 225 | − | // go to top of list | |
| 226 | − | KeyCode::Char('g') => match app.selected_tab { | |
| 227 | − | SelectedTab::Queue => app.queue_list.index = 0, | |
| 228 | − | SelectedTab::DirectoryBrowser => app.browser.selected = 0, | |
| 229 | − | SelectedTab::Playlists => app.pl_list.index = 0, | |
| 230 | − | }, | |
| 231 | − | ||
| 232 | − | // go to bottom of list | |
| 233 | − | KeyCode::Char('G') => match app.selected_tab { | |
| 234 | − | SelectedTab::Queue => app.queue_list.index = app.queue_list.list.len() - 1, | |
| 235 | − | SelectedTab::DirectoryBrowser => { | |
| 236 | − | app.browser.selected = app.browser.filetree.len() - 1 | |
| 237 | − | } | |
| 238 | − | SelectedTab::Playlists => app.pl_list.index = app.pl_list.list.len() - 1, | |
| 239 | − | }, | |
| 251 | + | // Change playlist name | |
| 252 | + | KeyCode::Char('e') => app.change_playlist_name()?, | |
| 240 | 253 | ||
| 241 | − | // Change playlist name | |
| 242 | − | KeyCode::Char('e') => app.change_playlist_name()?, | |
| 243 | − | _ => {} | |
| 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(); | |
| 260 | + | } | |
| 261 | + | _ => {} | |
| 262 | + | } | |
| 244 | 263 | } | |
| 245 | 264 | } | |
| 246 | 265 | Ok(()) | |