remove cli mod, dependent methods

This commit is contained in:
krolxon 2024-05-09 00:30:46 +05:30
parent cef5f73478
commit 1187e4f0b5
7 changed files with 17 additions and 319 deletions

215
Cargo.lock generated
View File

@ -20,54 +20,6 @@ version = "0.2.18"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5c6cb57a04249c6480766f7f7cef5467412af1490f8d1e243141daddada3264f" 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]] [[package]]
name = "autocfg" name = "autocfg"
version = "1.2.0" version = "1.2.0"
@ -113,52 +65,6 @@ version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" 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]] [[package]]
name = "compact_str" name = "compact_str"
version = "0.7.1" version = "0.7.1"
@ -219,12 +125,6 @@ version = "0.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8"
[[package]]
name = "heck"
version = "0.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea"
[[package]] [[package]]
name = "indoc" name = "indoc"
version = "2.0.5" version = "2.0.5"
@ -286,7 +186,7 @@ dependencies = [
"libc", "libc",
"log", "log",
"wasi", "wasi",
"windows-sys 0.48.0", "windows-sys",
] ]
[[package]] [[package]]
@ -324,7 +224,7 @@ dependencies = [
"libc", "libc",
"redox_syscall", "redox_syscall",
"smallvec", "smallvec",
"windows-targets 0.48.5", "windows-targets",
] ]
[[package]] [[package]]
@ -384,12 +284,10 @@ dependencies = [
name = "rmptui" name = "rmptui"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"clap",
"crossterm", "crossterm",
"mpd", "mpd",
"ratatui", "ratatui",
"rust-fuzzy-search", "rust-fuzzy-search",
"rust_fzf",
"simple-dmenu", "simple-dmenu",
] ]
@ -399,12 +297,6 @@ version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a157657054ffe556d8858504af8a672a054a6e0bd9e8ee531059100c0fa11bb2" checksum = "a157657054ffe556d8858504af8a672a054a6e0bd9e8ee531059100c0fa11bb2"
[[package]]
name = "rust_fzf"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "76a94b9c6a9880356cc6de038a52397509f8ac86a18c30d76da904b08fec2cb1"
[[package]] [[package]]
name = "rustversion" name = "rustversion"
version = "1.0.15" version = "1.0.15"
@ -481,12 +373,6 @@ version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f"
[[package]]
name = "strsim"
version = "0.11.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f"
[[package]] [[package]]
name = "strum" name = "strum"
version = "0.26.2" version = "0.26.2"
@ -502,7 +388,7 @@ version = "0.26.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c6cf59daf282c0a494ba14fd21610a0325f9f90ec9d1231dea26bcb1d696c946" checksum = "c6cf59daf282c0a494ba14fd21610a0325f9f90ec9d1231dea26bcb1d696c946"
dependencies = [ dependencies = [
"heck 0.4.1", "heck",
"proc-macro2", "proc-macro2",
"quote", "quote",
"rustversion", "rustversion",
@ -538,12 +424,6 @@ version = "0.1.11"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e51733f11c9c4f72aa0c160008246859e340b00807569a0da0e7a1079b27ba85" checksum = "e51733f11c9c4f72aa0c160008246859e340b00807569a0da0e7a1079b27ba85"
[[package]]
name = "utf8parse"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "711b9620af191e0cdc7468a8d14e709c3dcdb115b36f838e601583af800a370a"
[[package]] [[package]]
name = "version_check" name = "version_check"
version = "0.9.4" version = "0.9.4"
@ -584,16 +464,7 @@ version = "0.48.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9"
dependencies = [ dependencies = [
"windows-targets 0.48.5", "windows-targets",
]
[[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",
] ]
[[package]] [[package]]
@ -602,29 +473,13 @@ version = "0.48.5"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c"
dependencies = [ dependencies = [
"windows_aarch64_gnullvm 0.48.5", "windows_aarch64_gnullvm",
"windows_aarch64_msvc 0.48.5", "windows_aarch64_msvc",
"windows_i686_gnu 0.48.5", "windows_i686_gnu",
"windows_i686_msvc 0.48.5", "windows_i686_msvc",
"windows_x86_64_gnu 0.48.5", "windows_x86_64_gnu",
"windows_x86_64_gnullvm 0.48.5", "windows_x86_64_gnullvm",
"windows_x86_64_msvc 0.48.5", "windows_x86_64_msvc",
]
[[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",
] ]
[[package]] [[package]]
@ -633,90 +488,42 @@ version = "0.48.5"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8"
[[package]]
name = "windows_aarch64_gnullvm"
version = "0.52.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7088eed71e8b8dda258ecc8bac5fb1153c5cffaf2578fc8ff5d61e23578d3263"
[[package]] [[package]]
name = "windows_aarch64_msvc" name = "windows_aarch64_msvc"
version = "0.48.5" version = "0.48.5"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc"
[[package]]
name = "windows_aarch64_msvc"
version = "0.52.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9985fd1504e250c615ca5f281c3f7a6da76213ebd5ccc9561496568a2752afb6"
[[package]] [[package]]
name = "windows_i686_gnu" name = "windows_i686_gnu"
version = "0.48.5" version = "0.48.5"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" 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]] [[package]]
name = "windows_i686_msvc" name = "windows_i686_msvc"
version = "0.48.5" version = "0.48.5"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406"
[[package]]
name = "windows_i686_msvc"
version = "0.52.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "db3c2bf3d13d5b658be73463284eaf12830ac9a26a90c717b7f771dfe97487bf"
[[package]] [[package]]
name = "windows_x86_64_gnu" name = "windows_x86_64_gnu"
version = "0.48.5" version = "0.48.5"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" 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]] [[package]]
name = "windows_x86_64_gnullvm" name = "windows_x86_64_gnullvm"
version = "0.48.5" version = "0.48.5"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" 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]] [[package]]
name = "windows_x86_64_msvc" name = "windows_x86_64_msvc"
version = "0.48.5" version = "0.48.5"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" 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]] [[package]]
name = "zerocopy" name = "zerocopy"
version = "0.7.32" version = "0.7.32"

View File

@ -7,8 +7,6 @@ edition = "2021"
[dependencies] [dependencies]
mpd = "0.1.0" mpd = "0.1.0"
clap = { version = "4.0.29", features = ["derive"] }
rust_fzf = "0.3.1"
simple-dmenu = "0.1.0" simple-dmenu = "0.1.0"
ratatui = "0.26.2" ratatui = "0.26.2"
crossterm = "0.27.0" crossterm = "0.27.0"

View File

@ -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<Command>,
}
#[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,
}

View File

@ -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 /// Dmenu prompt for selecting songs
pub fn play_dmenu(&mut self) -> Result<()> { pub fn play_dmenu(&mut self) -> Result<()> {
is_installed("dmenu")?; is_installed("dmenu")?;
@ -178,27 +166,7 @@ impl Connection {
return Some(self.songs_filenames.get(i).unwrap().to_string()); return Some(self.songs_filenames.get(i).unwrap().to_string());
} }
} }
None 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 /// Gives title of current playing song

View File

@ -177,7 +177,7 @@ pub fn handle_key_events(key_event: KeyEvent, app: &mut App) -> AppResult<()> {
app.queue_list.index as u32 app.queue_list.index as u32
} else { } else {
app.queue_list.index += 1; app.queue_list.index += 1;
(current + 1) as u32 current + 1
}; };
app.conn.conn.swap(current, next)?; app.conn.conn.swap(current, next)?;
app.update_queue(); 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 app.queue_list.index as u32
} else { } else {
app.queue_list.index -= 1; app.queue_list.index -= 1;
(current - 1) as u32 current - 1
}; };
app.conn.conn.swap(current, prev)?; app.conn.conn.swap(current, prev)?;
app.update_queue(); app.update_queue();

View File

@ -1,6 +1,3 @@
/// Command line interface (deprecated)
pub mod cli;
/// Handle mpd connection /// Handle mpd connection
pub mod connection; pub mod connection;

View File

@ -1,50 +1,21 @@
#![allow(unused_imports)]
use clap::Parser;
use rmptui::app;
use rmptui::app::App; use rmptui::app::App;
use rmptui::app::AppResult; 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::Event;
use rmptui::event::event::EventHandler; use rmptui::event::event::EventHandler;
use rmptui::event::handler; use rmptui::event::handler;
use rmptui::tui; use rmptui::tui;
use std::env; use std::env;
use std::io; use std::io;
use ratatui::prelude::*;
use crossterm::event::{self, KeyCode, KeyEvent, KeyEventKind};
use ratatui::{
prelude::*,
symbols::border,
widgets::{block::*, *},
};
pub type Result<T> = core::result::Result<T, Error>; pub type Result<T> = core::result::Result<T, Error>;
pub type Error = Box<dyn std::error::Error>; pub type Error = Box<dyn std::error::Error>;
fn main() -> AppResult<()> { 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_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 env_port = env::var("MPD_PORT").unwrap_or_else(|_| "6600".to_string());
let mut app = App::builder(format!("{}:{}", env_host, env_port).as_str())?; 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 backend = CrosstermBackend::new(io::stderr());
let terminal = Terminal::new(backend)?; let terminal = Terminal::new(backend)?;
let events = EventHandler::new(1000); 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); let mut tui = tui::Tui::new(terminal, events);
tui.init()?; tui.init()?;
// update the directory // initial directory read
app.browser.update_directory(&mut app.conn).unwrap(); app.browser.update_directory(&mut app.conn).unwrap();
while app.running { while app.running {
tui.draw(app)?; tui.draw(&mut app)?;
match tui.events.next()? { match tui.events.next()? {
Event::Tick => app.tick(), 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::Mouse(_) => {}
Event::Resize(_, _) => {} Event::Resize(_, _) => {}
} }