Krolyxon
Commit 6e631a0

rmptui6e631a0

add unadded songs to queue on <space>

Author
krolxon
Date
2024-04-28 16:42 +0530
Parent
5eafc18
Commit
6e631a0520053c7d3435a193f61e89e695c91f08

+28 −15

3 files changed

  1. M src/app.rs +24 −11
  2. M src/handler.rs +1 −1
  3. M src/ui.rs +3 −3
M src/app.rs View
@@ -114,34 +114,47 @@ impl App {
114114 Ok(())
115115 }
116116
117− pub fn remove_from_current_playlist(&mut self) {
118− let mut file = String::new();
117+ pub fn handle_remove_or_from_current_playlist(&mut self) -> AppResult<()> {
119118 match self.selected_tab {
120119 SelectedTab::DirectoryBrowser => {
121− let (_, f) = self.browser.filetree.get(self.browser.selected).unwrap();
122− file.push_str(f);
120+ let (_, file) = self.browser.filetree.get(self.browser.selected).unwrap();
123121 self.browser.selected += 1;
122+ let mut status = false;
123+ for (i, song) in self.queue_list.list.clone().iter().enumerate() {
124+ if song.contains(file) {
125+ self.conn.conn.delete(i as u32).unwrap();
126+ status = true;
127+ }
128+ }
129+
130+ if !status {
131+ let song = self
132+ .conn
133+ .get_song_with_only_filename(&self.conn.get_full_path(&file).unwrap());
134+ self.conn.conn.push(&song)?;
135+ }
124136 }
125137
126138 SelectedTab::Queue => {
127− file = self
139+ let file = self
128140 .queue_list
129141 .list
130142 .get(self.queue_list.index)
131143 .unwrap()
132144 .to_string();
145+
146+ for (i, song) in self.queue_list.list.clone().iter().enumerate() {
147+ if song.contains(&file) {
148+ self.conn.conn.delete(i as u32).unwrap();
149+ }
150+ }
133151 }
134152
135153 _ => {}
136154 }
137155
138− for (i, song) in self.queue_list.list.clone().iter().enumerate() {
139− if song.contains(&file) {
140− self.conn.conn.delete(i as u32).unwrap();
141− }
142− }
143−
144156 self.update_queue();
157+ Ok(())
145158 }
146159
147160 pub fn cycle_tabls(&mut self) {
M src/handler.rs View
@@ -323,7 +323,7 @@ pub fn handle_key_events(key_event: KeyEvent, app: &mut App) -> AppResult<()> {
323323
324324 // Remove from Current Playlsit
325325 KeyCode::Char(' ') | KeyCode::Backspace => {
326− app.remove_from_current_playlist();
326+ app.handle_remove_or_from_current_playlist()?;
327327 }
328328
329329 // Change playlist name
M src/ui.rs View
@@ -62,9 +62,9 @@ fn draw_directory_browser(frame: &mut Frame, app: &mut App, size: Rect) {
6262 }
6363 }
6464 if status {
65− list.push(ListItem::new(s.clone().bold()));
65+ list.push(ListItem::new(s.clone().magenta().bold()));
6666 } else {
67− list.push(ListItem::new(Line::styled(s, Style::default())));
67+ list.push(ListItem::new(s.clone()));
6868 }
6969 } else {
7070 list.push(ListItem::new(Line::styled(
@@ -115,7 +115,7 @@ fn draw_queue(frame: &mut Frame, app: &mut App, size: Rect) {
115115 let mut items: Vec<ListItem> = vec![];
116116 for item in app.queue_list.list.iter() {
117117 if item.contains(&app.conn.current_song.file) {
118− items.push(ListItem::new(item.clone().bold()))
118+ items.push(ListItem::new(item.clone().magenta().bold()))
119119 } else {
120120 items.push(ListItem::new(item.clone()));
121121 }