Krolyxon
Commit 4bc03ce

rmptui4bc03ce

use filenames in queue instead of title

Author
krolxon
Date
2024-04-24 23:01 +0530
Parent
9e2b51c
Commit
4bc03ce8f4dea2ed6d68f2694bd095c9e3857e5e

+44 −20

4 files changed

  1. M README.md +3 −0
  2. M src/app.rs +15 −12
  3. M src/connection.rs +1 −1
  4. M src/handler.rs +25 −7
M README.md View
@@ -1 +1,4 @@
11 A MPD client in Rust
2+
3+# Keys
4+
M src/app.rs View
@@ -17,7 +17,6 @@ pub struct App {
1717 pub selected_tab: SelectedTab,
1818 }
1919
20−
2120 #[derive(Debug, PartialEq, Clone)]
2221 pub enum SelectedTab {
2322 SongList,
@@ -64,17 +63,21 @@ impl App {
6463 }
6564
6665 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+ // });
6777 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+ );
7881 }
7982
8083 pub fn update_queue(&mut self) {
@@ -97,7 +100,7 @@ impl App {
97100 self.selected_tab = match self.selected_tab {
98101 SelectedTab::SongList => SelectedTab::Queue,
99102 SelectedTab::Queue => SelectedTab::Playlists,
100− SelectedTab::Playlists=> SelectedTab::SongList,
103+ SelectedTab::Playlists => SelectedTab::SongList,
101104 };
102105 }
103106 }
M src/connection.rs View
@@ -48,7 +48,7 @@ impl Connection {
4848 pub fn play_dmenu(&mut self) -> Result<()> {
4949 is_installed("dmenu").map_err(|ex| ex)?;
5050 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");
5252 let index = get_choice_index(&self.songs_filenames, &op);
5353 let song = self.get_song_with_only_filename(ss.get(index).unwrap());
5454 self.push(&song)?;
M src/handler.rs View
@@ -2,7 +2,6 @@ use std::time::Duration;
22
33 use crate::app::{App, AppResult, SelectedTab};
44 use crossterm::event::{KeyCode, KeyEvent, KeyModifiers};
5−use ratatui::style::Modifier;
65
76 pub fn handle_key_events(key_event: KeyEvent, app: &mut App) -> AppResult<()> {
87 match key_event.code {
@@ -35,7 +34,13 @@ pub fn handle_key_events(key_event: KeyEvent, app: &mut App) -> AppResult<()> {
3534 );
3635 app.conn.push(&song)?;
3736 }
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+ }
3944 SelectedTab::Playlists => {
4045 app.conn
4146 .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<()> {
6368 // app.update_queue();
6469 }
6570
66− KeyCode::Char('d') => {
71+ // Dmenu prompt
72+ KeyCode::Char('D') => {
6773 app.conn.play_dmenu()?;
6874 }
6975
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+
7086 KeyCode::Right => {
7187 app.conn
7288 .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<()> {
102118 app.selected_tab = SelectedTab::Playlists;
103119 }
104120
105−
106121 KeyCode::Char('n') => {
107− app.conn.conn.next()?;
122+ app.conn.conn.next()?;
108123 }
109124
110125 KeyCode::Char('N') => {
111− app.conn.conn.prev()?;
126+ app.conn.conn.prev()?;
112127 }
113128
114129 // Volume controls
@@ -120,7 +135,10 @@ pub fn handle_key_events(key_event: KeyEvent, app: &mut App) -> AppResult<()> {
120135 app.conn.dec_volume(2);
121136 }
122137
123−
138+ // Delete highlighted song from the queue
139+ KeyCode::Char('d') => {
140+ app.conn.conn.delete(app.queue_list.index as u32)?;
141+ }
124142
125143 _ => {}
126144 }