From 1187e4f0b5414ccf1d5a84b9ab0284c9cebbb9af Mon Sep 17 00:00:00 2001 From: krolxon Date: Thu, 9 May 2024 00:30:46 +0530 Subject: [PATCH] remove cli mod, dependent methods --- Cargo.lock | 215 +++---------------------------------------- Cargo.toml | 2 - src/cli.rs | 43 --------- src/connection.rs | 32 ------- src/event/handler.rs | 4 +- src/lib.rs | 3 - src/main.rs | 37 +------- 7 files changed, 17 insertions(+), 319 deletions(-) delete mode 100755 src/cli.rs diff --git a/Cargo.lock b/Cargo.lock index 79b2484..3091635 100755 --- a/Cargo.lock +++ b/Cargo.lock @@ -20,54 +20,6 @@ version = "0.2.18" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5c6cb57a04249c6480766f7f7cef5467412af1490f8d1e243141daddada3264f" -[[package]] -name = "anstream" -version = "0.6.13" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d96bd03f33fe50a863e394ee9718a706f988b9079b20c3784fb726e7678b62fb" -dependencies = [ - "anstyle", - "anstyle-parse", - "anstyle-query", - "anstyle-wincon", - "colorchoice", - "utf8parse", -] - -[[package]] -name = "anstyle" -version = "1.0.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8901269c6307e8d93993578286ac0edf7f195079ffff5ebdeea6a59ffb7e36bc" - -[[package]] -name = "anstyle-parse" -version = "0.2.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c75ac65da39e5fe5ab759307499ddad880d724eed2f6ce5b5e8a26f4f387928c" -dependencies = [ - "utf8parse", -] - -[[package]] -name = "anstyle-query" -version = "1.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e28923312444cdd728e4738b3f9c9cac739500909bb3d3c94b43551b16517648" -dependencies = [ - "windows-sys 0.52.0", -] - -[[package]] -name = "anstyle-wincon" -version = "3.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1cd54b81ec8d6180e24654d0b371ad22fc3dd083b6ff8ba325b72e00c87660a7" -dependencies = [ - "anstyle", - "windows-sys 0.52.0", -] - [[package]] name = "autocfg" version = "1.2.0" @@ -113,52 +65,6 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" -[[package]] -name = "clap" -version = "4.5.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "90bc066a67923782aa8515dbaea16946c5bcc5addbd668bb80af688e53e548a0" -dependencies = [ - "clap_builder", - "clap_derive", -] - -[[package]] -name = "clap_builder" -version = "4.5.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ae129e2e766ae0ec03484e609954119f123cc1fe650337e155d03b022f24f7b4" -dependencies = [ - "anstream", - "anstyle", - "clap_lex", - "strsim", -] - -[[package]] -name = "clap_derive" -version = "4.5.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "528131438037fd55894f62d6e9f068b8f45ac57ffa77517819645d10aed04f64" -dependencies = [ - "heck 0.5.0", - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "clap_lex" -version = "0.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "98cc8fbded0c607b7ba9dd60cd98df59af97e84d24e49c8557331cfc26d301ce" - -[[package]] -name = "colorchoice" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "acbf1af155f9b9ef647e42cdc158db4b64a1b61f743629225fde6f3e0be2a7c7" - [[package]] name = "compact_str" version = "0.7.1" @@ -219,12 +125,6 @@ version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" -[[package]] -name = "heck" -version = "0.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" - [[package]] name = "indoc" version = "2.0.5" @@ -286,7 +186,7 @@ dependencies = [ "libc", "log", "wasi", - "windows-sys 0.48.0", + "windows-sys", ] [[package]] @@ -324,7 +224,7 @@ dependencies = [ "libc", "redox_syscall", "smallvec", - "windows-targets 0.48.5", + "windows-targets", ] [[package]] @@ -384,12 +284,10 @@ dependencies = [ name = "rmptui" version = "0.1.0" dependencies = [ - "clap", "crossterm", "mpd", "ratatui", "rust-fuzzy-search", - "rust_fzf", "simple-dmenu", ] @@ -399,12 +297,6 @@ version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a157657054ffe556d8858504af8a672a054a6e0bd9e8ee531059100c0fa11bb2" -[[package]] -name = "rust_fzf" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "76a94b9c6a9880356cc6de038a52397509f8ac86a18c30d76da904b08fec2cb1" - [[package]] name = "rustversion" version = "1.0.15" @@ -481,12 +373,6 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" -[[package]] -name = "strsim" -version = "0.11.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f" - [[package]] name = "strum" version = "0.26.2" @@ -502,7 +388,7 @@ version = "0.26.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c6cf59daf282c0a494ba14fd21610a0325f9f90ec9d1231dea26bcb1d696c946" dependencies = [ - "heck 0.4.1", + "heck", "proc-macro2", "quote", "rustversion", @@ -538,12 +424,6 @@ version = "0.1.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e51733f11c9c4f72aa0c160008246859e340b00807569a0da0e7a1079b27ba85" -[[package]] -name = "utf8parse" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "711b9620af191e0cdc7468a8d14e709c3dcdb115b36f838e601583af800a370a" - [[package]] name = "version_check" version = "0.9.4" @@ -584,16 +464,7 @@ version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" dependencies = [ - "windows-targets 0.48.5", -] - -[[package]] -name = "windows-sys" -version = "0.52.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" -dependencies = [ - "windows-targets 0.52.5", + "windows-targets", ] [[package]] @@ -602,29 +473,13 @@ version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" dependencies = [ - "windows_aarch64_gnullvm 0.48.5", - "windows_aarch64_msvc 0.48.5", - "windows_i686_gnu 0.48.5", - "windows_i686_msvc 0.48.5", - "windows_x86_64_gnu 0.48.5", - "windows_x86_64_gnullvm 0.48.5", - "windows_x86_64_msvc 0.48.5", -] - -[[package]] -name = "windows-targets" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6f0713a46559409d202e70e28227288446bf7841d3211583a4b53e3f6d96e7eb" -dependencies = [ - "windows_aarch64_gnullvm 0.52.5", - "windows_aarch64_msvc 0.52.5", - "windows_i686_gnu 0.52.5", - "windows_i686_gnullvm", - "windows_i686_msvc 0.52.5", - "windows_x86_64_gnu 0.52.5", - "windows_x86_64_gnullvm 0.52.5", - "windows_x86_64_msvc 0.52.5", + "windows_aarch64_gnullvm", + "windows_aarch64_msvc", + "windows_i686_gnu", + "windows_i686_msvc", + "windows_x86_64_gnu", + "windows_x86_64_gnullvm", + "windows_x86_64_msvc", ] [[package]] @@ -633,90 +488,42 @@ version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" -[[package]] -name = "windows_aarch64_gnullvm" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7088eed71e8b8dda258ecc8bac5fb1153c5cffaf2578fc8ff5d61e23578d3263" - [[package]] name = "windows_aarch64_msvc" version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" -[[package]] -name = "windows_aarch64_msvc" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9985fd1504e250c615ca5f281c3f7a6da76213ebd5ccc9561496568a2752afb6" - [[package]] name = "windows_i686_gnu" version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" -[[package]] -name = "windows_i686_gnu" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "88ba073cf16d5372720ec942a8ccbf61626074c6d4dd2e745299726ce8b89670" - -[[package]] -name = "windows_i686_gnullvm" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87f4261229030a858f36b459e748ae97545d6f1ec60e5e0d6a3d32e0dc232ee9" - [[package]] name = "windows_i686_msvc" version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" -[[package]] -name = "windows_i686_msvc" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "db3c2bf3d13d5b658be73463284eaf12830ac9a26a90c717b7f771dfe97487bf" - [[package]] name = "windows_x86_64_gnu" version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" -[[package]] -name = "windows_x86_64_gnu" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4e4246f76bdeff09eb48875a0fd3e2af6aada79d409d33011886d3e1581517d9" - [[package]] name = "windows_x86_64_gnullvm" version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" -[[package]] -name = "windows_x86_64_gnullvm" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "852298e482cd67c356ddd9570386e2862b5673c85bd5f88df9ab6802b334c596" - [[package]] name = "windows_x86_64_msvc" version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" -[[package]] -name = "windows_x86_64_msvc" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bec47e5bfd1bff0eeaf6d8b485cc1074891a197ab4225d504cb7a1ab88b02bf0" - [[package]] name = "zerocopy" version = "0.7.32" diff --git a/Cargo.toml b/Cargo.toml index ef3cf49..034cea9 100755 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,8 +7,6 @@ edition = "2021" [dependencies] mpd = "0.1.0" -clap = { version = "4.0.29", features = ["derive"] } -rust_fzf = "0.3.1" simple-dmenu = "0.1.0" ratatui = "0.26.2" crossterm = "0.27.0" diff --git a/src/cli.rs b/src/cli.rs deleted file mode 100755 index 2992952..0000000 --- a/src/cli.rs +++ /dev/null @@ -1,43 +0,0 @@ -use clap::{Parser, Subcommand}; - -#[derive(Parser, Debug)] -#[clap(version, about, author = "krolyxon")] -/// MPD client made with Rust -pub struct Args { - /// No TUI - #[arg(short= 'n', default_value="false")] - pub tui: bool, - - #[command(subcommand)] - pub command: Option, -} - -#[derive(Debug, Subcommand)] -pub enum Command { - #[command(arg_required_else_help = true, long_flag = "volume" , short_flag = 'v')] - /// Set Volume - Volume { - vol: String, - }, - - /// Use dmenu for selection - #[command(long_flag = "dmenu" , short_flag = 'd')] - Dmenu, - - /// Use Fzf for selection - #[command(long_flag = "fzf" , short_flag = 'f')] - Fzf, - - /// Check Status - #[command(long_flag = "status" , short_flag = 's')] - Status, - - /// Pause playback - #[command(long_flag = "pause" , short_flag = 'p')] - Pause, - - /// Toggle Playback - #[command(long_flag = "toggle" , short_flag = 't')] - Toggle, - -} diff --git a/src/connection.rs b/src/connection.rs index 972ee10..9fde2e2 100755 --- a/src/connection.rs +++ b/src/connection.rs @@ -61,18 +61,6 @@ impl Connection { }) } - /// Fzf prompt for selecting song - pub fn play_fzf(&mut self) -> Result<()> { - is_installed("fzf")?; - let ss = &self.songs_filenames; - let fzf_choice = rust_fzf::select(ss.clone(), Vec::new()).unwrap(); - let index = get_choice_index(&self.songs_filenames, fzf_choice.first().unwrap()); - let song = self.get_song_with_only_filename(ss.get(index).unwrap()); - self.push(&song)?; - - Ok(()) - } - /// Dmenu prompt for selecting songs pub fn play_dmenu(&mut self) -> Result<()> { is_installed("dmenu")?; @@ -178,27 +166,7 @@ impl Connection { return Some(self.songs_filenames.get(i).unwrap().to_string()); } } - None - - // Ok(filename.to_string()) - } - - /// Print status to stdout - pub fn status(&mut self) { - let current_song = self.conn.currentsong(); - let status = self.conn.status().unwrap(); - - if current_song.is_ok() && status.state != State::Stop { - let song = current_song.unwrap(); - if let Some(s) = song { - println!("{} - {}", s.artist.unwrap(), s.title.unwrap()); - } - } - println!( - "volume: {}\trepeat: {}\trandom: {}\tsingle: {}\tconsume: {}", - status.volume, status.repeat, status.random, status.single, status.consume - ); } /// Gives title of current playing song diff --git a/src/event/handler.rs b/src/event/handler.rs index 0978458..3663006 100755 --- a/src/event/handler.rs +++ b/src/event/handler.rs @@ -177,7 +177,7 @@ pub fn handle_key_events(key_event: KeyEvent, app: &mut App) -> AppResult<()> { app.queue_list.index as u32 } else { app.queue_list.index += 1; - (current + 1) as u32 + current + 1 }; app.conn.conn.swap(current, next)?; app.update_queue(); @@ -190,7 +190,7 @@ pub fn handle_key_events(key_event: KeyEvent, app: &mut App) -> AppResult<()> { app.queue_list.index as u32 } else { app.queue_list.index -= 1; - (current - 1) as u32 + current - 1 }; app.conn.conn.swap(current, prev)?; app.update_queue(); diff --git a/src/lib.rs b/src/lib.rs index f06847f..6744922 100755 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,6 +1,3 @@ -/// Command line interface (deprecated) -pub mod cli; - /// Handle mpd connection pub mod connection; diff --git a/src/main.rs b/src/main.rs index ce64c85..d8441d3 100755 --- a/src/main.rs +++ b/src/main.rs @@ -1,50 +1,21 @@ -#![allow(unused_imports)] -use clap::Parser; -use rmptui::app; use rmptui::app::App; use rmptui::app::AppResult; -use rmptui::cli::Args; -use rmptui::cli::Command; -use rmptui::connection::Connection; use rmptui::event::event::Event; use rmptui::event::event::EventHandler; use rmptui::event::handler; use rmptui::tui; use std::env; use std::io; - -use crossterm::event::{self, KeyCode, KeyEvent, KeyEventKind}; -use ratatui::{ - prelude::*, - symbols::border, - widgets::{block::*, *}, -}; +use ratatui::prelude::*; pub type Result = core::result::Result; pub type Error = Box; fn main() -> AppResult<()> { - let args = Args::parse(); let env_host = env::var("MPD_HOST").unwrap_or_else(|_| "127.0.0.1".to_string()); let env_port = env::var("MPD_PORT").unwrap_or_else(|_| "6600".to_string()); let mut app = App::builder(format!("{}:{}", env_host, env_port).as_str())?; - if !args.tui { - handle_tui(&mut app)?; - } else { - match args.command { - Some(Command::Dmenu) => app.conn.play_dmenu()?, - Some(Command::Fzf) => app.conn.play_fzf().unwrap(), - Some(Command::Status) => app.conn.status(), - Some(Command::Pause) => app.conn.pause(), - Some(Command::Toggle) => app.conn.toggle_pause(), - _ => {} - } - } - Ok(()) -} - -pub fn handle_tui(app: &mut App) -> AppResult<()> { let backend = CrosstermBackend::new(io::stderr()); let terminal = Terminal::new(backend)?; let events = EventHandler::new(1000); @@ -52,14 +23,14 @@ pub fn handle_tui(app: &mut App) -> AppResult<()> { let mut tui = tui::Tui::new(terminal, events); tui.init()?; - // update the directory + // initial directory read app.browser.update_directory(&mut app.conn).unwrap(); while app.running { - tui.draw(app)?; + tui.draw(&mut app)?; match tui.events.next()? { Event::Tick => app.tick(), - Event::Key(key_event) => handler::handle_key_events(key_event, app)?, + Event::Key(key_event) => handler::handle_key_events(key_event, &mut app)?, Event::Mouse(_) => {} Event::Resize(_, _) => {} }