From cbf90ce5f0e6bd833c73fb66a3618fc2adc59da3 Mon Sep 17 00:00:00 2001 From: Marty Sluijtman Date: Thu, 19 Jun 2025 16:48:22 +0200 Subject: [PATCH] Some finetuning - Added 'shuffle' command - Added more info to 'list' command --- Cargo.lock | 2 +- Cargo.toml | 2 +- src/main.rs | 46 +++++++++++++++++++++++++++++++--------------- 3 files changed, 33 insertions(+), 17 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index f597fe5..ef67e47 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -249,7 +249,7 @@ dependencies = [ [[package]] name = "noise" -version = "0.1.0" +version = "0.1.2" dependencies = [ "clap", "libnotify", diff --git a/Cargo.toml b/Cargo.toml index fc54abd..26144d2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "noise" -version = "0.1.1" +version = "0.1.2" edition = "2024" [dependencies] diff --git a/src/main.rs b/src/main.rs index 7744290..12be065 100644 --- a/src/main.rs +++ b/src/main.rs @@ -64,11 +64,16 @@ enum Commands { append: bool, }, /// List items in the current queueueu - List {}, + List { + #[arg(short, long)] + file: bool, + }, // Add { // #[arg(short, long)] // position: Option, // }, + /// Shuffles the current queueue + Shuffle {}, } fn main() { @@ -84,7 +89,7 @@ fn main() { // let mut conn = Client::connect(host).unwrap(); - let mut conn = Client::connect(host).expect("Things"); + let mut conn = Client::connect(host).expect("Connection failed"); // let mut conn = match Client::connect(host) { // Ok(conn) => conn, @@ -95,13 +100,17 @@ fn main() { match cmd { Commands::Play { track } => { if let Some(i) = track { - conn.switch(*i).unwrap() + conn.switch(*i).unwrap(); } else { conn.play().unwrap(); } + let status = get_status(conn, cli.verbose, n); + println!("{status}"); } - Commands::Stop {} => conn.stop().unwrap(), + Commands::Stop {} => { + conn.stop().unwrap(); + } Commands::Toggle {} => { if conn.status().unwrap().state == State::Stop { @@ -125,7 +134,17 @@ fn main() { println!("{status}"); } - Commands::List {} => print_songs(conn.queue().unwrap()), + Commands::List { file } => conn.queue().unwrap().iter().for_each(|x| { + println!( + "{:<02} {}", + x.place.unwrap().pos, + if *file { + x.file.clone() + } else { + format_song(x.clone()) + } + ) + }), Commands::Update {} => { let thing = conn.update().unwrap(); @@ -204,10 +223,13 @@ fn main() { println!("Crossfade disabled") } } - } // Commands::Add { position } => { - // // insert_or_append(conn, *position); - // println!("{:?}", position); - // } + } + + Commands::Shuffle {} => { + send_notification("Shuffling queueueu...".to_string(), n); + println!("Shuffling queueueu..."); + conn.shuffle(..).unwrap(); + } } } else { let status = get_status(conn, cli.verbose, n); @@ -216,12 +238,6 @@ fn main() { } } -fn print_songs(songs: Vec) -> () { - songs - .iter() - .for_each(|x| println!("{}", format_song(x.clone()))); -} - fn format_song(song: Song) -> String { format!("{} - {}", song.artist.unwrap(), song.title.unwrap()) }