rmptuib04423d
add swapping keys
+30 −0
2 files changed
- M README.md +3 −0
- M src/event/handler.rs +27 −0
| @@ -12,6 +12,8 @@ A MPD client in Rust | |||
| 12 | 12 | - `D` to get dmenu prompt | |
| 13 | 13 | - `j` OR `Down` to scroll down | |
| 14 | 14 | - `k` OR `Up` to scroll up | |
| 15 | + | - `J` to swap highlighted song with next one | |
| 16 | + | - `K` to swap highlighted song with previous one | |
| 15 | 17 | - `l` OR `Right` add song to playlist or go inside the directory | |
| 16 | 18 | - `h` OR `Left` to go back to previous directory | |
| 17 | 19 | - `Tab` to cycle through tabs | |
| @@ -41,3 +43,4 @@ A MPD client in Rust | |||
| 41 | 43 | - [x] metadata based tree view | |
| 42 | 44 | - [x] view playlist | |
| 43 | 45 | - [x] change playlist name | |
| 46 | + | - [ ] add lyrics fetcher | |
| @@ -175,6 +175,33 @@ pub fn handle_key_events(key_event: KeyEvent, app: &mut App) -> AppResult<()> { | |||
| 175 | 175 | app.update_queue(); | |
| 176 | 176 | } | |
| 177 | 177 | ||
| 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 | + | } | |
| 190 | + | ||
| 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(); | |
| 202 | + | } | |
| 203 | + | ||
| 204 | + | ||
| 178 | 205 | // Update MPD database | |
| 179 | 206 | KeyCode::Char('U') => { | |
| 180 | 207 | app.conn.conn.rescan()?; | |