From baa2e095d9b165b05246db2551c275d115f99de8 Mon Sep 17 00:00:00 2001 From: talwat <83217276+talwat@users.noreply.github.com> Date: Sun, 6 Oct 2024 09:36:06 +0200 Subject: [PATCH] feat: add minimalist flag --- Cargo.lock | 2 +- Cargo.toml | 2 +- src/main.rs | 4 ++++ src/player/ui.rs | 17 +++++++++++++---- 4 files changed, 19 insertions(+), 6 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 210f319..55c4b9c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -982,7 +982,7 @@ checksum = "a7a70ba024b9dc04c27ea2f0c0548feb474ec5c54bba33a7f72f873a39d07b24" [[package]] name = "lowfi" -version = "1.3.4" +version = "1.3.5" dependencies = [ "Inflector", "arc-swap", diff --git a/Cargo.toml b/Cargo.toml index 2798fab..765df21 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "lowfi" -version = "1.3.4" +version = "1.3.5" edition = "2021" description = "An extremely simple lofi player." license = "MIT" diff --git a/src/main.rs b/src/main.rs index 3bb4fef..a863147 100644 --- a/src/main.rs +++ b/src/main.rs @@ -13,6 +13,10 @@ struct Args { #[clap(long, short)] alternate: bool, + /// Whether to hide the bottom control bar. + #[clap(long, short)] + minimalist: bool, + /// The command that was ran. /// This is [None] if no command was specified. #[command(subcommand)] diff --git a/src/player/ui.rs b/src/player/ui.rs index c0a10ea..5aa5eee 100644 --- a/src/player/ui.rs +++ b/src/player/ui.rs @@ -57,7 +57,7 @@ lazy_static! { /// /// `volume_timer` is a bit strange, but it tracks how long the `volume` bar /// has been displayed for, so that it's only displayed for a certain amount of frames. -async fn interface(player: Arc) -> eyre::Result<()> { +async fn interface(player: Arc, minimalist: bool) -> eyre::Result<()> { loop { let action = components::action(&player, WIDTH); @@ -78,8 +78,17 @@ async fn interface(player: Arc) -> eyre::Result<()> { let controls = components::controls(WIDTH); + let menu = if minimalist { + vec![action, middle] + } else { + vec![action, middle, controls] + }; + // Formats the menu properly - let menu = [action, middle, controls].map(|x| format!("│ {} │\r\n", x.reset()).to_string()); + let menu: Vec = menu + .into_iter() + .map(|x| format!("│ {} │\r\n", x.reset()).to_string()) + .collect(); crossterm::execute!( stdout(), @@ -89,7 +98,7 @@ async fn interface(player: Arc) -> eyre::Result<()> { Print(menu.join("")), Print(format!("└{}┘", "─".repeat(WIDTH + 2))), MoveToColumn(0), - MoveUp(4) + MoveUp(menu.len() as u16 + 1) )?; sleep(Duration::from_secs_f32(FRAME_DELTA)).await; @@ -117,7 +126,7 @@ pub async fn start(queue: Arc, sender: Sender, args: Args) -> )?; } - task::spawn(interface(Arc::clone(&queue))); + task::spawn(interface(Arc::clone(&queue), args.minimalist)); loop { let event::Event::Key(event) = event::read()? else {