rmptui4bc03ce
use filenames in queue instead of title
+44 −20
4 files changed
- M README.md +3 −0
- M src/app.rs +15 −12
- M src/connection.rs +1 −1
- M src/handler.rs +25 −7
| @@ -1 +1,4 @@ | |||
| 1 | 1 | A MPD client in Rust | |
| 2 | + | ||
| 3 | + | # Keys | |
| 4 | + | ||
| @@ -17,7 +17,6 @@ pub struct App { | |||
| 17 | 17 | pub selected_tab: SelectedTab, | |
| 18 | 18 | } | |
| 19 | 19 | ||
| 20 | − | ||
| 21 | 20 | #[derive(Debug, PartialEq, Clone)] | |
| 22 | 21 | pub enum SelectedTab { | |
| 23 | 22 | SongList, | |
| @@ -64,17 +63,21 @@ impl App { | |||
| 64 | 63 | } | |
| 65 | 64 | ||
| 66 | 65 | pub fn get_queue(conn: &mut Connection, vec: &mut Vec<String>) { | |
| 66 | + | // conn.conn.queue().unwrap().into_iter().for_each(|x| { | |
| 67 | + | // if let Some(title) = x.title { | |
| 68 | + | // if let Some(artist) = x.artist { | |
| 69 | + | // vec.push(format!("{} - {}", artist, title)); | |
| 70 | + | // } else { | |
| 71 | + | // vec.push(title) | |
| 72 | + | // } | |
| 73 | + | // } else { | |
| 74 | + | // vec.push(x.file) | |
| 75 | + | // } | |
| 76 | + | // }); | |
| 67 | 77 | conn.conn.queue().unwrap().into_iter().for_each(|x| { | |
| 68 | − | if let Some(title) = x.title { | |
| 69 | − | if let Some(artist) = x.artist { | |
| 70 | − | vec.push(format!("{} - {}", artist, title)); | |
| 71 | − | } else { | |
| 72 | − | vec.push(title) | |
| 73 | − | } | |
| 74 | − | } else { | |
| 75 | − | vec.push(x.file) | |
| 76 | − | } | |
| 77 | − | }); | |
| 78 | + | vec.push(x.file); | |
| 79 | + | } | |
| 80 | + | ); | |
| 78 | 81 | } | |
| 79 | 82 | ||
| 80 | 83 | pub fn update_queue(&mut self) { | |
| @@ -97,7 +100,7 @@ impl App { | |||
| 97 | 100 | self.selected_tab = match self.selected_tab { | |
| 98 | 101 | SelectedTab::SongList => SelectedTab::Queue, | |
| 99 | 102 | SelectedTab::Queue => SelectedTab::Playlists, | |
| 100 | − | SelectedTab::Playlists=> SelectedTab::SongList, | |
| 103 | + | SelectedTab::Playlists => SelectedTab::SongList, | |
| 101 | 104 | }; | |
| 102 | 105 | } | |
| 103 | 106 | } | |
| @@ -48,7 +48,7 @@ impl Connection { | |||
| 48 | 48 | pub fn play_dmenu(&mut self) -> Result<()> { | |
| 49 | 49 | is_installed("dmenu").map_err(|ex| ex)?; | |
| 50 | 50 | let ss: Vec<&str> = self.songs_filenames.iter().map(|x| x.as_str()).collect(); | |
| 51 | − | let op = dmenu!(iter &ss; args "-l", "30"); | |
| 51 | + | let op = dmenu!(iter &ss; args "-p", "Choose a song: ", "-l", "30"); | |
| 52 | 52 | let index = get_choice_index(&self.songs_filenames, &op); | |
| 53 | 53 | let song = self.get_song_with_only_filename(ss.get(index).unwrap()); | |
| 54 | 54 | self.push(&song)?; | |
| @@ -2,7 +2,6 @@ use std::time::Duration; | |||
| 2 | 2 | ||
| 3 | 3 | use crate::app::{App, AppResult, SelectedTab}; | |
| 4 | 4 | use crossterm::event::{KeyCode, KeyEvent, KeyModifiers}; | |
| 5 | − | use ratatui::style::Modifier; | |
| 6 | 5 | ||
| 7 | 6 | pub fn handle_key_events(key_event: KeyEvent, app: &mut App) -> AppResult<()> { | |
| 8 | 7 | match key_event.code { | |
| @@ -35,7 +34,13 @@ pub fn handle_key_events(key_event: KeyEvent, app: &mut App) -> AppResult<()> { | |||
| 35 | 34 | ); | |
| 36 | 35 | app.conn.push(&song)?; | |
| 37 | 36 | } | |
| 38 | − | SelectedTab::Queue => {} | |
| 37 | + | SelectedTab::Queue => { | |
| 38 | + | let song = app.conn.get_song_with_only_filename( | |
| 39 | + | app.queue_list.list.get(app.queue_list.index).unwrap(), | |
| 40 | + | ); | |
| 41 | + | app.conn.push(&song)?; | |
| 42 | + | ||
| 43 | + | } | |
| 39 | 44 | SelectedTab::Playlists => { | |
| 40 | 45 | app.conn | |
| 41 | 46 | .push_playlist(app.pl_list.list.get(app.pl_list.index).unwrap())?; | |
| @@ -63,10 +68,21 @@ pub fn handle_key_events(key_event: KeyEvent, app: &mut App) -> AppResult<()> { | |||
| 63 | 68 | // app.update_queue(); | |
| 64 | 69 | } | |
| 65 | 70 | ||
| 66 | − | KeyCode::Char('d') => { | |
| 71 | + | // Dmenu prompt | |
| 72 | + | KeyCode::Char('D') => { | |
| 67 | 73 | app.conn.play_dmenu()?; | |
| 68 | 74 | } | |
| 69 | 75 | ||
| 76 | + | ||
| 77 | + | // add to queue | |
| 78 | + | KeyCode::Char('a') => { | |
| 79 | + | let song = app.conn.get_song_with_only_filename( | |
| 80 | + | app.conn.songs_filenames.get(app.song_list.index).unwrap(), | |
| 81 | + | ); | |
| 82 | + | app.conn.conn.push(&song)?; | |
| 83 | + | } | |
| 84 | + | ||
| 85 | + | ||
| 70 | 86 | KeyCode::Right => { | |
| 71 | 87 | app.conn | |
| 72 | 88 | .push_playlist(app.pl_list.list.get(app.pl_list.index).unwrap())?; | |
| @@ -102,13 +118,12 @@ pub fn handle_key_events(key_event: KeyEvent, app: &mut App) -> AppResult<()> { | |||
| 102 | 118 | app.selected_tab = SelectedTab::Playlists; | |
| 103 | 119 | } | |
| 104 | 120 | ||
| 105 | − | ||
| 106 | 121 | KeyCode::Char('n') => { | |
| 107 | − | app.conn.conn.next()?; | |
| 122 | + | app.conn.conn.next()?; | |
| 108 | 123 | } | |
| 109 | 124 | ||
| 110 | 125 | KeyCode::Char('N') => { | |
| 111 | − | app.conn.conn.prev()?; | |
| 126 | + | app.conn.conn.prev()?; | |
| 112 | 127 | } | |
| 113 | 128 | ||
| 114 | 129 | // Volume controls | |
| @@ -120,7 +135,10 @@ pub fn handle_key_events(key_event: KeyEvent, app: &mut App) -> AppResult<()> { | |||
| 120 | 135 | app.conn.dec_volume(2); | |
| 121 | 136 | } | |
| 122 | 137 | ||
| 123 | − | ||
| 138 | + | // Delete highlighted song from the queue | |
| 139 | + | KeyCode::Char('d') => { | |
| 140 | + | app.conn.conn.delete(app.queue_list.index as u32)?; | |
| 141 | + | } | |
| 124 | 142 | ||
| 125 | 143 | _ => {} | |
| 126 | 144 | } | |