fix dmenu_play adding song even when exit without seleciton
This commit is contained in:
parent
0ded1507aa
commit
3d569cbf79
|
|
@ -69,9 +69,11 @@ impl Connection {
|
||||||
is_installed("dmenu")?;
|
is_installed("dmenu")?;
|
||||||
let ss: Vec<&str> = self.songs_filenames.iter().map(|x| x.as_str()).collect();
|
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 op = dmenu!(iter &ss; args "-p", "Choose a song: ", "-l", "30");
|
||||||
let index = get_choice_index(&self.songs_filenames, &op);
|
let index = ss.iter().position(|s| s == &op);
|
||||||
let song = self.get_song_with_only_filename(ss.get(index).unwrap());
|
if let Some(i) = index {
|
||||||
self.push(&song)?;
|
let song = self.get_song_with_only_filename(ss.get(i).unwrap());
|
||||||
|
self.push(&song)?;
|
||||||
|
}
|
||||||
Ok(())
|
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
|
/// Checks if given program is installed in your system
|
||||||
fn is_installed(ss: &str) -> Result<()> {
|
fn is_installed(ss: &str) -> Result<()> {
|
||||||
let output = Command::new("which")
|
let output = Command::new("which")
|
||||||
|
|
|
||||||
Reference in New Issue