aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xREADME.md4
-rwxr-xr-xsrc/connection.rs26
2 files changed, 16 insertions, 14 deletions
diff --git a/README.md b/README.md
index 35b6583..2495b6b 100755
--- a/README.md
+++ b/README.md
@@ -34,6 +34,10 @@ A MPD client in Rust
- `g` to go to top of list
- `G` to go to bottom of list
+### Prerequisites
+- [MPD](https://wiki.archlinux.org/title/Music_Player_Daemon) installed and configured.
+- [dmenu](https://tools.suckless.org/dmenu/) (optional)
+
### TODO
- [x] fix performance issues
- [x] improvements on queue control
diff --git a/src/connection.rs b/src/connection.rs
index 84ca664..7afb3d2 100755
--- a/src/connection.rs
+++ b/src/connection.rs
@@ -66,14 +66,16 @@ impl Connection {
/// Dmenu prompt for selecting songs
pub fn play_dmenu(&mut self) -> Result<()> {
- 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 = 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)?;
+ if 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 = 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(())
}
@@ -240,15 +242,11 @@ impl Connection {
}
/// Checks if given program is installed in your system
-fn is_installed(ss: &str) -> Result<()> {
+fn is_installed(ss: &str) -> bool {
let output = Command::new("which")
.arg(ss)
.output()
.expect("Failed to execute command");
- if output.status.success() {
- Ok(())
- } else {
- let err = format!("{} not installed", ss);
- Err(err.into())
- }
+
+ output.status.success()
}