aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorkrolxon <krolyxon@tutanota.com>2024-05-12 17:30:55 +0530
committerkrolxon <krolyxon@tutanota.com>2024-05-12 17:30:55 +0530
commit3d569cbf7903cfdf56a6056d9a0771cd2279188b (patch)
tree91e9c60a2d5b8a392b40f1b89b779411b11d9d92
parent0ded1507aa0910ba6246ef81cc619a459aac7c9a (diff)
fix dmenu_play adding song even when exit without seleciton
-rwxr-xr-xsrc/connection.rs18
1 files changed, 5 insertions, 13 deletions
diff --git a/src/connection.rs b/src/connection.rs
index bbe14f6..84ca664 100755
--- a/src/connection.rs
+++ b/src/connection.rs
@@ -69,9 +69,11 @@ impl Connection {
is_installed("dmenu")?;
let ss: Vec<&str> = self.songs_filenames.iter().map(|x| x.as_str()).collect();
let op = dmenu!(iter &ss; args "-p", "Choose a song: ", "-l", "30");
- let index = get_choice_index(&self.songs_filenames, &op);
- let song = self.get_song_with_only_filename(ss.get(index).unwrap());
- self.push(&song)?;
+ let index = ss.iter().position(|s| s == &op);
+ if let Some(i) = index {
+ let song = self.get_song_with_only_filename(ss.get(i).unwrap());
+ self.push(&song)?;
+ }
Ok(())
}
@@ -237,16 +239,6 @@ impl Connection {
}
}
-/// Gets the index of the string from the Vector
-fn get_choice_index(ss: &[String], selection: &str) -> usize {
- let mut choice: usize = 0;
- if let Some(index) = ss.iter().position(|s| s == selection) {
- choice = index;
- }
-
- choice
-}
-
/// Checks if given program is installed in your system
fn is_installed(ss: &str) -> Result<()> {
let output = Command::new("which")