rmptui3d569cb
fix dmenu_play adding song even when exit without seleciton
+5 −13
1 file changed
- M src/connection.rs +5 −13
| @@ -69,9 +69,11 @@ impl Connection { | |||
| 69 | 69 | is_installed("dmenu")?; | |
| 70 | 70 | let ss: Vec<&str> = self.songs_filenames.iter().map(|x| x.as_str()).collect(); | |
| 71 | 71 | let op = dmenu!(iter &ss; args "-p", "Choose a song: ", "-l", "30"); | |
| 72 | − | let index = get_choice_index(&self.songs_filenames, &op); | |
| 73 | − | let song = self.get_song_with_only_filename(ss.get(index).unwrap()); | |
| 74 | − | self.push(&song)?; | |
| 72 | + | let index = ss.iter().position(|s| s == &op); | |
| 73 | + | if let Some(i) = index { | |
| 74 | + | let song = self.get_song_with_only_filename(ss.get(i).unwrap()); | |
| 75 | + | self.push(&song)?; | |
| 76 | + | } | |
| 75 | 77 | Ok(()) | |
| 76 | 78 | } | |
| 77 | 79 | ||
| @@ -237,16 +239,6 @@ impl Connection { | |||
| 237 | 239 | } | |
| 238 | 240 | } | |
| 239 | 241 | ||
| 240 | − | /// Gets the index of the string from the Vector | |
| 241 | − | fn get_choice_index(ss: &[String], selection: &str) -> usize { | |
| 242 | − | let mut choice: usize = 0; | |
| 243 | − | if let Some(index) = ss.iter().position(|s| s == selection) { | |
| 244 | − | choice = index; | |
| 245 | − | } | |
| 246 | − | ||
| 247 | − | choice | |
| 248 | − | } | |
| 249 | − | ||
| 250 | 242 | /// Checks if given program is installed in your system | |
| 251 | 243 | fn is_installed(ss: &str) -> Result<()> { | |
| 252 | 244 | let output = Command::new("which") | |