Compare commits
1 commit
Author | SHA1 | Date | |
---|---|---|---|
eddf2231e9 |
5 changed files with 45 additions and 30 deletions
2
Cargo.lock
generated
2
Cargo.lock
generated
|
@ -268,7 +268,7 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "noise"
|
||||
version = "0.1.8"
|
||||
version = "0.1.9"
|
||||
dependencies = [
|
||||
"clap",
|
||||
"clap_complete",
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
[package]
|
||||
name = "noise"
|
||||
version = "0.1.8"
|
||||
version = "0.1.9"
|
||||
edition = "2024"
|
||||
authors = ["Nox Sluijtman"]
|
||||
|
||||
|
|
15
src/main.rs
15
src/main.rs
|
@ -5,7 +5,7 @@ use noise::{commands::Noise, parser::*};
|
|||
|
||||
use clap::{Command, CommandFactory, Parser};
|
||||
use clap_complete::{generate, Generator};
|
||||
use mpd::Client;
|
||||
use mpd::{error::Error, Client};
|
||||
use std::io;
|
||||
|
||||
fn print_completions<G: Generator>(generator: G, cmd: &mut Command) {
|
||||
|
@ -17,19 +17,22 @@ fn print_completions<G: Generator>(generator: G, cmd: &mut Command) {
|
|||
);
|
||||
}
|
||||
|
||||
fn main() {
|
||||
fn main() -> Result<(), Error> {
|
||||
let cli = Cli::parse();
|
||||
|
||||
if let Some(completions) = cli.completions {
|
||||
let mut cmd = Cli::command();
|
||||
eprintln!("Generatig completion file for {completions:?}...");
|
||||
print_completions(completions, &mut cmd);
|
||||
return;
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
let host = cli.host.unwrap_or("localhost:6600".into());
|
||||
|
||||
let mut conn = Client::connect(host).expect("Connection failed");
|
||||
let mut conn = match Client::connect(host) {
|
||||
Ok(client) => client,
|
||||
Err(err) => return Err(err),
|
||||
};
|
||||
|
||||
if let Some(cmd) = &cli.command {
|
||||
match cmd {
|
||||
|
@ -63,7 +66,7 @@ fn main() {
|
|||
| Commands::Volume { .. }
|
||||
| Commands::Shuffle = cmd
|
||||
{
|
||||
return;
|
||||
return Ok(());
|
||||
}
|
||||
}
|
||||
let _things: Vec<String> = conn
|
||||
|
@ -72,6 +75,6 @@ fn main() {
|
|||
.iter()
|
||||
.map(|x| x.place.unwrap().pos.to_string())
|
||||
.collect();
|
||||
// println!("{things:?}");
|
||||
println!("{}", conn.get_status(cli.verbose));
|
||||
return Ok(());
|
||||
}
|
||||
|
|
|
@ -3,7 +3,7 @@ extern crate mpd;
|
|||
|
||||
use libnotify::Notification;
|
||||
use mpd::{Client, Query, Song, State, Term};
|
||||
use std::time::Duration;
|
||||
use std::{env, time::Duration};
|
||||
|
||||
pub trait Noise {
|
||||
fn find(&mut self, query: &Vec<String>, max: Option<u32>, append: bool);
|
||||
|
@ -174,12 +174,23 @@ impl Noise for Client {
|
|||
State::Play => "playing",
|
||||
};
|
||||
|
||||
fn to_mins_string(dur: Duration) -> String {
|
||||
let seconds = dur.as_secs();
|
||||
|
||||
let minutes = seconds / 60;
|
||||
let rem_seconds = seconds % 60;
|
||||
|
||||
format!("{minutes:02}:{rem_seconds:02}")
|
||||
}
|
||||
|
||||
let duration = status.time.map_or("".into(), |(stamp, total)| {
|
||||
let stamp = to_mins_string(stamp);
|
||||
let total = to_mins_string(total);
|
||||
format!("{stamp}/{total}")
|
||||
});
|
||||
|
||||
// let pos_in_queue = format!("{current_pos}/{queue_lenth}");
|
||||
|
||||
output.push(format!("[{state}] {duration}"));
|
||||
|
||||
output.join("\n")
|
||||
|
@ -197,16 +208,16 @@ fn format_song(song: Song) -> String {
|
|||
// fn get_status(client: &mut Client, verbose: bool) -> String {}
|
||||
|
||||
fn send_notification(body: &str) {
|
||||
let key = "XDG_SESSION_TYPE";
|
||||
match env::var(key) {
|
||||
Ok(key) => {
|
||||
if key != "tty" {
|
||||
libnotify::init("noise").unwrap();
|
||||
let notify = Notification::new("Noise", Some(body), None);
|
||||
notify.show().unwrap();
|
||||
libnotify::uninit();
|
||||
}
|
||||
}
|
||||
Err(_) => return,
|
||||
}
|
||||
|
||||
fn to_mins_string(dur: Duration) -> String {
|
||||
let seconds = dur.as_secs();
|
||||
|
||||
let minutes = seconds / 60;
|
||||
let rem_seconds = seconds % 60;
|
||||
|
||||
format!("{minutes:02}:{rem_seconds:02}")
|
||||
}
|
||||
|
|
|
@ -29,6 +29,13 @@ pub struct Cli {
|
|||
|
||||
#[derive(Subcommand, Debug, PartialEq)]
|
||||
pub enum Commands {
|
||||
/// Stops playing
|
||||
Stop,
|
||||
/// Play queueueu
|
||||
Play {
|
||||
#[arg(value_hint = ValueHint::CommandString)]
|
||||
track: Option<u32>,
|
||||
},
|
||||
/// Toggle MPD playback
|
||||
#[command(visible_alias = "t")]
|
||||
Toggle,
|
||||
|
@ -37,13 +44,6 @@ pub enum Commands {
|
|||
Next,
|
||||
/// Revert to the previous track
|
||||
Prev,
|
||||
/// Stops playing
|
||||
Stop,
|
||||
/// Play queueueu
|
||||
Play {
|
||||
#[arg(value_hint = ValueHint::CommandString)]
|
||||
track: Option<u32>,
|
||||
},
|
||||
/// Set or get crossfade
|
||||
#[command(visible_alias = "fade")]
|
||||
Crossfade {
|
||||
|
@ -52,8 +52,6 @@ pub enum Commands {
|
|||
},
|
||||
// ///Update still needs some work
|
||||
// Update,
|
||||
/// Return currently playing song
|
||||
Current,
|
||||
/// Clear current queueueu
|
||||
Clear,
|
||||
/// Query database
|
||||
|
@ -70,6 +68,8 @@ pub enum Commands {
|
|||
// #[arg(short, long)]
|
||||
// insert: Option<u32>,
|
||||
},
|
||||
/// Return currently playing song
|
||||
Current,
|
||||
/// Query database autistically
|
||||
#[command(visible_alias = "fd")]
|
||||
Find {
|
||||
|
@ -109,6 +109,7 @@ pub enum Commands {
|
|||
#[arg(value_hint = ValueHint::Other)]
|
||||
percentage: Option<i8>,
|
||||
},
|
||||
/// Remove the current track
|
||||
Munch,
|
||||
Length,
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue