Krolyxon
Commit 1187e4f

rmptui1187e4f

remove cli mod, dependent methods

Author
krolxon
Date
2024-05-09 00:30 +0530
Parent
cef5f73
Commit
1187e4f0b5414ccf1d5a84b9ab0284c9cebbb9af

+17 −319

7 files changed

  1. M Cargo.lock +11 −204
  2. M Cargo.toml +0 −2
  3. D src/cli.rs +0 −43
  4. M src/connection.rs +0 −32
  5. M src/event/handler.rs +2 −2
  6. M src/lib.rs +0 −3
  7. M src/main.rs +4 −33
M Cargo.lock View
@@ -20,54 +20,6 @@ version = "0.2.18"
2020 source = "registry+https://github.com/rust-lang/crates.io-index"
2121 checksum = "5c6cb57a04249c6480766f7f7cef5467412af1490f8d1e243141daddada3264f"
2222
23−[[package]]
24−name = "anstream"
25−version = "0.6.13"
26−source = "registry+https://github.com/rust-lang/crates.io-index"
27−checksum = "d96bd03f33fe50a863e394ee9718a706f988b9079b20c3784fb726e7678b62fb"
28−dependencies = [
29− "anstyle",
30− "anstyle-parse",
31− "anstyle-query",
32− "anstyle-wincon",
33− "colorchoice",
34− "utf8parse",
35−]
36−
37−[[package]]
38−name = "anstyle"
39−version = "1.0.6"
40−source = "registry+https://github.com/rust-lang/crates.io-index"
41−checksum = "8901269c6307e8d93993578286ac0edf7f195079ffff5ebdeea6a59ffb7e36bc"
42−
43−[[package]]
44−name = "anstyle-parse"
45−version = "0.2.3"
46−source = "registry+https://github.com/rust-lang/crates.io-index"
47−checksum = "c75ac65da39e5fe5ab759307499ddad880d724eed2f6ce5b5e8a26f4f387928c"
48−dependencies = [
49− "utf8parse",
50−]
51−
52−[[package]]
53−name = "anstyle-query"
54−version = "1.0.2"
55−source = "registry+https://github.com/rust-lang/crates.io-index"
56−checksum = "e28923312444cdd728e4738b3f9c9cac739500909bb3d3c94b43551b16517648"
57−dependencies = [
58− "windows-sys 0.52.0",
59−]
60−
61−[[package]]
62−name = "anstyle-wincon"
63−version = "3.0.2"
64−source = "registry+https://github.com/rust-lang/crates.io-index"
65−checksum = "1cd54b81ec8d6180e24654d0b371ad22fc3dd083b6ff8ba325b72e00c87660a7"
66−dependencies = [
67− "anstyle",
68− "windows-sys 0.52.0",
69−]
70−
7123 [[package]]
7224 name = "autocfg"
7325 version = "1.2.0"
@@ -113,52 +65,6 @@ version = "1.0.0"
11365 source = "registry+https://github.com/rust-lang/crates.io-index"
11466 checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
11567
116−[[package]]
117−name = "clap"
118−version = "4.5.4"
119−source = "registry+https://github.com/rust-lang/crates.io-index"
120−checksum = "90bc066a67923782aa8515dbaea16946c5bcc5addbd668bb80af688e53e548a0"
121−dependencies = [
122− "clap_builder",
123− "clap_derive",
124−]
125−
126−[[package]]
127−name = "clap_builder"
128−version = "4.5.2"
129−source = "registry+https://github.com/rust-lang/crates.io-index"
130−checksum = "ae129e2e766ae0ec03484e609954119f123cc1fe650337e155d03b022f24f7b4"
131−dependencies = [
132− "anstream",
133− "anstyle",
134− "clap_lex",
135− "strsim",
136−]
137−
138−[[package]]
139−name = "clap_derive"
140−version = "4.5.4"
141−source = "registry+https://github.com/rust-lang/crates.io-index"
142−checksum = "528131438037fd55894f62d6e9f068b8f45ac57ffa77517819645d10aed04f64"
143−dependencies = [
144− "heck 0.5.0",
145− "proc-macro2",
146− "quote",
147− "syn",
148−]
149−
150−[[package]]
151−name = "clap_lex"
152−version = "0.7.0"
153−source = "registry+https://github.com/rust-lang/crates.io-index"
154−checksum = "98cc8fbded0c607b7ba9dd60cd98df59af97e84d24e49c8557331cfc26d301ce"
155−
156−[[package]]
157−name = "colorchoice"
158−version = "1.0.0"
159−source = "registry+https://github.com/rust-lang/crates.io-index"
160−checksum = "acbf1af155f9b9ef647e42cdc158db4b64a1b61f743629225fde6f3e0be2a7c7"
161−
16268 [[package]]
16369 name = "compact_str"
16470 version = "0.7.1"
@@ -219,12 +125,6 @@ version = "0.4.1"
219125 source = "registry+https://github.com/rust-lang/crates.io-index"
220126 checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8"
221127
222−[[package]]
223−name = "heck"
224−version = "0.5.0"
225−source = "registry+https://github.com/rust-lang/crates.io-index"
226−checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea"
227−
228128 [[package]]
229129 name = "indoc"
230130 version = "2.0.5"
@@ -286,7 +186,7 @@ dependencies = [
286186 "libc",
287187 "log",
288188 "wasi",
289− "windows-sys 0.48.0",
189+ "windows-sys",
290190 ]
291191
292192 [[package]]
@@ -324,7 +224,7 @@ dependencies = [
324224 "libc",
325225 "redox_syscall",
326226 "smallvec",
327− "windows-targets 0.48.5",
227+ "windows-targets",
328228 ]
329229
330230 [[package]]
@@ -384,12 +284,10 @@ dependencies = [
384284 name = "rmptui"
385285 version = "0.1.0"
386286 dependencies = [
387− "clap",
388287 "crossterm",
389288 "mpd",
390289 "ratatui",
391290 "rust-fuzzy-search",
392− "rust_fzf",
393291 "simple-dmenu",
394292 ]
395293
@@ -399,12 +297,6 @@ version = "0.1.1"
399297 source = "registry+https://github.com/rust-lang/crates.io-index"
400298 checksum = "a157657054ffe556d8858504af8a672a054a6e0bd9e8ee531059100c0fa11bb2"
401299
402−[[package]]
403−name = "rust_fzf"
404−version = "0.3.1"
405−source = "registry+https://github.com/rust-lang/crates.io-index"
406−checksum = "76a94b9c6a9880356cc6de038a52397509f8ac86a18c30d76da904b08fec2cb1"
407−
408300 [[package]]
409301 name = "rustversion"
410302 version = "1.0.15"
@@ -481,12 +373,6 @@ version = "1.1.0"
481373 source = "registry+https://github.com/rust-lang/crates.io-index"
482374 checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f"
483375
484−[[package]]
485−name = "strsim"
486−version = "0.11.1"
487−source = "registry+https://github.com/rust-lang/crates.io-index"
488−checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f"
489−
490376 [[package]]
491377 name = "strum"
492378 version = "0.26.2"
@@ -502,7 +388,7 @@ version = "0.26.2"
502388 source = "registry+https://github.com/rust-lang/crates.io-index"
503389 checksum = "c6cf59daf282c0a494ba14fd21610a0325f9f90ec9d1231dea26bcb1d696c946"
504390 dependencies = [
505− "heck 0.4.1",
391+ "heck",
506392 "proc-macro2",
507393 "quote",
508394 "rustversion",
@@ -538,12 +424,6 @@ version = "0.1.11"
538424 source = "registry+https://github.com/rust-lang/crates.io-index"
539425 checksum = "e51733f11c9c4f72aa0c160008246859e340b00807569a0da0e7a1079b27ba85"
540426
541−[[package]]
542−name = "utf8parse"
543−version = "0.2.1"
544−source = "registry+https://github.com/rust-lang/crates.io-index"
545−checksum = "711b9620af191e0cdc7468a8d14e709c3dcdb115b36f838e601583af800a370a"
546−
547427 [[package]]
548428 name = "version_check"
549429 version = "0.9.4"
@@ -584,16 +464,7 @@ version = "0.48.0"
584464 source = "registry+https://github.com/rust-lang/crates.io-index"
585465 checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9"
586466 dependencies = [
587− "windows-targets 0.48.5",
588−]
589−
590−[[package]]
591−name = "windows-sys"
592−version = "0.52.0"
593−source = "registry+https://github.com/rust-lang/crates.io-index"
594−checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d"
595−dependencies = [
596− "windows-targets 0.52.5",
467+ "windows-targets",
597468 ]
598469
599470 [[package]]
@@ -602,29 +473,13 @@ version = "0.48.5"
602473 source = "registry+https://github.com/rust-lang/crates.io-index"
603474 checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c"
604475 dependencies = [
605− "windows_aarch64_gnullvm 0.48.5",
606− "windows_aarch64_msvc 0.48.5",
607− "windows_i686_gnu 0.48.5",
608− "windows_i686_msvc 0.48.5",
609− "windows_x86_64_gnu 0.48.5",
610− "windows_x86_64_gnullvm 0.48.5",
611− "windows_x86_64_msvc 0.48.5",
612−]
613−
614−[[package]]
615−name = "windows-targets"
616−version = "0.52.5"
617−source = "registry+https://github.com/rust-lang/crates.io-index"
618−checksum = "6f0713a46559409d202e70e28227288446bf7841d3211583a4b53e3f6d96e7eb"
619−dependencies = [
620− "windows_aarch64_gnullvm 0.52.5",
621− "windows_aarch64_msvc 0.52.5",
622− "windows_i686_gnu 0.52.5",
623− "windows_i686_gnullvm",
624− "windows_i686_msvc 0.52.5",
625− "windows_x86_64_gnu 0.52.5",
626− "windows_x86_64_gnullvm 0.52.5",
627− "windows_x86_64_msvc 0.52.5",
476+ "windows_aarch64_gnullvm",
477+ "windows_aarch64_msvc",
478+ "windows_i686_gnu",
479+ "windows_i686_msvc",
480+ "windows_x86_64_gnu",
481+ "windows_x86_64_gnullvm",
482+ "windows_x86_64_msvc",
628483 ]
629484
630485 [[package]]
@@ -633,90 +488,42 @@ version = "0.48.5"
633488 source = "registry+https://github.com/rust-lang/crates.io-index"
634489 checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8"
635490
636−[[package]]
637−name = "windows_aarch64_gnullvm"
638−version = "0.52.5"
639−source = "registry+https://github.com/rust-lang/crates.io-index"
640−checksum = "7088eed71e8b8dda258ecc8bac5fb1153c5cffaf2578fc8ff5d61e23578d3263"
641−
642491 [[package]]
643492 name = "windows_aarch64_msvc"
644493 version = "0.48.5"
645494 source = "registry+https://github.com/rust-lang/crates.io-index"
646495 checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc"
647496
648−[[package]]
649−name = "windows_aarch64_msvc"
650−version = "0.52.5"
651−source = "registry+https://github.com/rust-lang/crates.io-index"
652−checksum = "9985fd1504e250c615ca5f281c3f7a6da76213ebd5ccc9561496568a2752afb6"
653−
654497 [[package]]
655498 name = "windows_i686_gnu"
656499 version = "0.48.5"
657500 source = "registry+https://github.com/rust-lang/crates.io-index"
658501 checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e"
659502
660−[[package]]
661−name = "windows_i686_gnu"
662−version = "0.52.5"
663−source = "registry+https://github.com/rust-lang/crates.io-index"
664−checksum = "88ba073cf16d5372720ec942a8ccbf61626074c6d4dd2e745299726ce8b89670"
665−
666−[[package]]
667−name = "windows_i686_gnullvm"
668−version = "0.52.5"
669−source = "registry+https://github.com/rust-lang/crates.io-index"
670−checksum = "87f4261229030a858f36b459e748ae97545d6f1ec60e5e0d6a3d32e0dc232ee9"
671−
672503 [[package]]
673504 name = "windows_i686_msvc"
674505 version = "0.48.5"
675506 source = "registry+https://github.com/rust-lang/crates.io-index"
676507 checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406"
677508
678−[[package]]
679−name = "windows_i686_msvc"
680−version = "0.52.5"
681−source = "registry+https://github.com/rust-lang/crates.io-index"
682−checksum = "db3c2bf3d13d5b658be73463284eaf12830ac9a26a90c717b7f771dfe97487bf"
683−
684509 [[package]]
685510 name = "windows_x86_64_gnu"
686511 version = "0.48.5"
687512 source = "registry+https://github.com/rust-lang/crates.io-index"
688513 checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e"
689514
690−[[package]]
691−name = "windows_x86_64_gnu"
692−version = "0.52.5"
693−source = "registry+https://github.com/rust-lang/crates.io-index"
694−checksum = "4e4246f76bdeff09eb48875a0fd3e2af6aada79d409d33011886d3e1581517d9"
695−
696515 [[package]]
697516 name = "windows_x86_64_gnullvm"
698517 version = "0.48.5"
699518 source = "registry+https://github.com/rust-lang/crates.io-index"
700519 checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc"
701520
702−[[package]]
703−name = "windows_x86_64_gnullvm"
704−version = "0.52.5"
705−source = "registry+https://github.com/rust-lang/crates.io-index"
706−checksum = "852298e482cd67c356ddd9570386e2862b5673c85bd5f88df9ab6802b334c596"
707−
708521 [[package]]
709522 name = "windows_x86_64_msvc"
710523 version = "0.48.5"
711524 source = "registry+https://github.com/rust-lang/crates.io-index"
712525 checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538"
713526
714−[[package]]
715−name = "windows_x86_64_msvc"
716−version = "0.52.5"
717−source = "registry+https://github.com/rust-lang/crates.io-index"
718−checksum = "bec47e5bfd1bff0eeaf6d8b485cc1074891a197ab4225d504cb7a1ab88b02bf0"
719−
720527 [[package]]
721528 name = "zerocopy"
722529 version = "0.7.32"
M Cargo.toml View
@@ -7,8 +7,6 @@ edition = "2021"
77
88 [dependencies]
99 mpd = "0.1.0"
10−clap = { version = "4.0.29", features = ["derive"] }
11−rust_fzf = "0.3.1"
1210 simple-dmenu = "0.1.0"
1311 ratatui = "0.26.2"
1412 crossterm = "0.27.0"
D src/cli.rs View
@@ -1,43 +0,0 @@
1−use clap::{Parser, Subcommand};
2−
3−#[derive(Parser, Debug)]
4−#[clap(version, about, author = "krolyxon")]
5−/// MPD client made with Rust
6−pub struct Args {
7− /// No TUI
8− #[arg(short= 'n', default_value="false")]
9− pub tui: bool,
10−
11− #[command(subcommand)]
12− pub command: Option<Command>,
13−}
14−
15−#[derive(Debug, Subcommand)]
16−pub enum Command {
17− #[command(arg_required_else_help = true, long_flag = "volume" , short_flag = 'v')]
18− /// Set Volume
19− Volume {
20− vol: String,
21− },
22−
23− /// Use dmenu for selection
24− #[command(long_flag = "dmenu" , short_flag = 'd')]
25− Dmenu,
26−
27− /// Use Fzf for selection
28− #[command(long_flag = "fzf" , short_flag = 'f')]
29− Fzf,
30−
31− /// Check Status
32− #[command(long_flag = "status" , short_flag = 's')]
33− Status,
34−
35− /// Pause playback
36− #[command(long_flag = "pause" , short_flag = 'p')]
37− Pause,
38−
39− /// Toggle Playback
40− #[command(long_flag = "toggle" , short_flag = 't')]
41− Toggle,
42−
43−}
M src/connection.rs View
@@ -61,18 +61,6 @@ impl Connection {
6161 })
6262 }
6363
64− /// Fzf prompt for selecting song
65− pub fn play_fzf(&mut self) -> Result<()> {
66− is_installed("fzf")?;
67− let ss = &self.songs_filenames;
68− let fzf_choice = rust_fzf::select(ss.clone(), Vec::new()).unwrap();
69− let index = get_choice_index(&self.songs_filenames, fzf_choice.first().unwrap());
70− let song = self.get_song_with_only_filename(ss.get(index).unwrap());
71− self.push(&song)?;
72−
73− Ok(())
74− }
75−
7664 /// Dmenu prompt for selecting songs
7765 pub fn play_dmenu(&mut self) -> Result<()> {
7866 is_installed("dmenu")?;
@@ -178,27 +166,7 @@ impl Connection {
178166 return Some(self.songs_filenames.get(i).unwrap().to_string());
179167 }
180168 }
181−
182169 None
183−
184− // Ok(filename.to_string())
185− }
186−
187− /// Print status to stdout
188− pub fn status(&mut self) {
189− let current_song = self.conn.currentsong();
190− let status = self.conn.status().unwrap();
191−
192− if current_song.is_ok() && status.state != State::Stop {
193− let song = current_song.unwrap();
194− if let Some(s) = song {
195− println!("{} - {}", s.artist.unwrap(), s.title.unwrap());
196− }
197− }
198− println!(
199− "volume: {}\trepeat: {}\trandom: {}\tsingle: {}\tconsume: {}",
200− status.volume, status.repeat, status.random, status.single, status.consume
201− );
202170 }
203171
204172 /// Gives title of current playing song
M src/event/handler.rs View
@@ -177,7 +177,7 @@ pub fn handle_key_events(key_event: KeyEvent, app: &mut App) -> AppResult<()> {
177177 app.queue_list.index as u32
178178 } else {
179179 app.queue_list.index += 1;
180− (current + 1) as u32
180+ current + 1
181181 };
182182 app.conn.conn.swap(current, next)?;
183183 app.update_queue();
@@ -190,7 +190,7 @@ pub fn handle_key_events(key_event: KeyEvent, app: &mut App) -> AppResult<()> {
190190 app.queue_list.index as u32
191191 } else {
192192 app.queue_list.index -= 1;
193− (current - 1) as u32
193+ current - 1
194194 };
195195 app.conn.conn.swap(current, prev)?;
196196 app.update_queue();
M src/lib.rs View
@@ -1,6 +1,3 @@
1−/// Command line interface (deprecated)
2−pub mod cli;
3−
41 /// Handle mpd connection
52 pub mod connection;
63
M src/main.rs View
@@ -1,50 +1,21 @@
1−#![allow(unused_imports)]
2−use clap::Parser;
3−use rmptui::app;
41 use rmptui::app::App;
52 use rmptui::app::AppResult;
6−use rmptui::cli::Args;
7−use rmptui::cli::Command;
8−use rmptui::connection::Connection;
93 use rmptui::event::event::Event;
104 use rmptui::event::event::EventHandler;
115 use rmptui::event::handler;
126 use rmptui::tui;
137 use std::env;
148 use std::io;
15−
16−use crossterm::event::{self, KeyCode, KeyEvent, KeyEventKind};
17−use ratatui::{
18− prelude::*,
19− symbols::border,
20− widgets::{block::*, *},
21−};
9+use ratatui::prelude::*;
2210
2311 pub type Result<T> = core::result::Result<T, Error>;
2412 pub type Error = Box<dyn std::error::Error>;
2513
2614 fn main() -> AppResult<()> {
27− let args = Args::parse();
2815 let env_host = env::var("MPD_HOST").unwrap_or_else(|_| "127.0.0.1".to_string());
2916 let env_port = env::var("MPD_PORT").unwrap_or_else(|_| "6600".to_string());
3017 let mut app = App::builder(format!("{}:{}", env_host, env_port).as_str())?;
3118
32− if !args.tui {
33− handle_tui(&mut app)?;
34− } else {
35− match args.command {
36− Some(Command::Dmenu) => app.conn.play_dmenu()?,
37− Some(Command::Fzf) => app.conn.play_fzf().unwrap(),
38− Some(Command::Status) => app.conn.status(),
39− Some(Command::Pause) => app.conn.pause(),
40− Some(Command::Toggle) => app.conn.toggle_pause(),
41− _ => {}
42− }
43− }
44− Ok(())
45−}
46−
47−pub fn handle_tui(app: &mut App) -> AppResult<()> {
4819 let backend = CrosstermBackend::new(io::stderr());
4920 let terminal = Terminal::new(backend)?;
5021 let events = EventHandler::new(1000);
@@ -52,14 +23,14 @@ pub fn handle_tui(app: &mut App) -> AppResult<()> {
5223 let mut tui = tui::Tui::new(terminal, events);
5324 tui.init()?;
5425
55− // update the directory
26+ // initial directory read
5627 app.browser.update_directory(&mut app.conn).unwrap();
5728
5829 while app.running {
59− tui.draw(app)?;
30+ tui.draw(&mut app)?;
6031 match tui.events.next()? {
6132 Event::Tick => app.tick(),
62− Event::Key(key_event) => handler::handle_key_events(key_event, app)?,
33+ Event::Key(key_event) => handler::handle_key_events(key_event, &mut app)?,
6334 Event::Mouse(_) => {}
6435 Event::Resize(_, _) => {}
6536 }