Krolyxon
Commit b04423d

rmptuib04423d

add swapping keys

Author
krolxon
Date
2024-05-02 14:44 +0530
Parent
b7fc6bc
Commit
b04423d18d25bf889001a20d7bc8853de4816754

+30 −0

2 files changed

  1. M README.md +3 −0
  2. M src/event/handler.rs +27 −0
M README.md View
@@ -12,6 +12,8 @@ A MPD client in Rust
1212 - `D` to get dmenu prompt
1313 - `j` OR `Down` to scroll down
1414 - `k` OR `Up` to scroll up
15+- `J` to swap highlighted song with next one
16+- `K` to swap highlighted song with previous one
1517 - `l` OR `Right` add song to playlist or go inside the directory
1618 - `h` OR `Left` to go back to previous directory
1719 - `Tab` to cycle through tabs
@@ -41,3 +43,4 @@ A MPD client in Rust
4143 - [x] metadata based tree view
4244 - [x] view playlist
4345 - [x] change playlist name
46+- [ ] add lyrics fetcher
M src/event/handler.rs View
@@ -175,6 +175,33 @@ pub fn handle_key_events(key_event: KeyEvent, app: &mut App) -> AppResult<()> {
175175 app.update_queue();
176176 }
177177
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+
178205 // Update MPD database
179206 KeyCode::Char('U') => {
180207 app.conn.conn.rescan()?;