Krolyxon
Commit e5e6928

rmptuie5e6928

get basic stuff working

Author
krolxon
Date
2024-04-22 02:42 +0530
Parent
a025aad
Commit
e5e69281caed57c5d76d77e3a5260f37a2673548

+391 −0

6 files changed

  1. A .gitignore +1 −0
  2. A Cargo.lock +253 −0
  3. A Cargo.toml +11 −0
  4. M README.md +0 −0
  5. A src/connection.rs +92 −0
  6. A src/main.rs +34 −0
A .gitignore View
@@ -0,0 +1 @@
1+/target
A Cargo.lock View
@@ -0,0 +1,253 @@
1+# This file is automatically @generated by Cargo.
2+# It is not intended for manual editing.
3+version = 3
4+
5+[[package]]
6+name = "anstream"
7+version = "0.6.13"
8+source = "registry+https://github.com/rust-lang/crates.io-index"
9+checksum = "d96bd03f33fe50a863e394ee9718a706f988b9079b20c3784fb726e7678b62fb"
10+dependencies = [
11+ "anstyle",
12+ "anstyle-parse",
13+ "anstyle-query",
14+ "anstyle-wincon",
15+ "colorchoice",
16+ "utf8parse",
17+]
18+
19+[[package]]
20+name = "anstyle"
21+version = "1.0.6"
22+source = "registry+https://github.com/rust-lang/crates.io-index"
23+checksum = "8901269c6307e8d93993578286ac0edf7f195079ffff5ebdeea6a59ffb7e36bc"
24+
25+[[package]]
26+name = "anstyle-parse"
27+version = "0.2.3"
28+source = "registry+https://github.com/rust-lang/crates.io-index"
29+checksum = "c75ac65da39e5fe5ab759307499ddad880d724eed2f6ce5b5e8a26f4f387928c"
30+dependencies = [
31+ "utf8parse",
32+]
33+
34+[[package]]
35+name = "anstyle-query"
36+version = "1.0.2"
37+source = "registry+https://github.com/rust-lang/crates.io-index"
38+checksum = "e28923312444cdd728e4738b3f9c9cac739500909bb3d3c94b43551b16517648"
39+dependencies = [
40+ "windows-sys",
41+]
42+
43+[[package]]
44+name = "anstyle-wincon"
45+version = "3.0.2"
46+source = "registry+https://github.com/rust-lang/crates.io-index"
47+checksum = "1cd54b81ec8d6180e24654d0b371ad22fc3dd083b6ff8ba325b72e00c87660a7"
48+dependencies = [
49+ "anstyle",
50+ "windows-sys",
51+]
52+
53+[[package]]
54+name = "bufstream"
55+version = "0.1.4"
56+source = "registry+https://github.com/rust-lang/crates.io-index"
57+checksum = "40e38929add23cdf8a366df9b0e088953150724bcbe5fc330b0d8eb3b328eec8"
58+
59+[[package]]
60+name = "clap"
61+version = "4.5.4"
62+source = "registry+https://github.com/rust-lang/crates.io-index"
63+checksum = "90bc066a67923782aa8515dbaea16946c5bcc5addbd668bb80af688e53e548a0"
64+dependencies = [
65+ "clap_builder",
66+ "clap_derive",
67+]
68+
69+[[package]]
70+name = "clap_builder"
71+version = "4.5.2"
72+source = "registry+https://github.com/rust-lang/crates.io-index"
73+checksum = "ae129e2e766ae0ec03484e609954119f123cc1fe650337e155d03b022f24f7b4"
74+dependencies = [
75+ "anstream",
76+ "anstyle",
77+ "clap_lex",
78+ "strsim",
79+]
80+
81+[[package]]
82+name = "clap_derive"
83+version = "4.5.4"
84+source = "registry+https://github.com/rust-lang/crates.io-index"
85+checksum = "528131438037fd55894f62d6e9f068b8f45ac57ffa77517819645d10aed04f64"
86+dependencies = [
87+ "heck",
88+ "proc-macro2",
89+ "quote",
90+ "syn",
91+]
92+
93+[[package]]
94+name = "clap_lex"
95+version = "0.7.0"
96+source = "registry+https://github.com/rust-lang/crates.io-index"
97+checksum = "98cc8fbded0c607b7ba9dd60cd98df59af97e84d24e49c8557331cfc26d301ce"
98+
99+[[package]]
100+name = "colorchoice"
101+version = "1.0.0"
102+source = "registry+https://github.com/rust-lang/crates.io-index"
103+checksum = "acbf1af155f9b9ef647e42cdc158db4b64a1b61f743629225fde6f3e0be2a7c7"
104+
105+[[package]]
106+name = "heck"
107+version = "0.5.0"
108+source = "registry+https://github.com/rust-lang/crates.io-index"
109+checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea"
110+
111+[[package]]
112+name = "mpd"
113+version = "0.1.0"
114+source = "registry+https://github.com/rust-lang/crates.io-index"
115+checksum = "2e12cace5746cb0aa78faa6cd2caec9f9c01882fc0e6b54d34685a2d3303ea34"
116+dependencies = [
117+ "bufstream",
118+]
119+
120+[[package]]
121+name = "proc-macro2"
122+version = "1.0.81"
123+source = "registry+https://github.com/rust-lang/crates.io-index"
124+checksum = "3d1597b0c024618f09a9c3b8655b7e430397a36d23fdafec26d6965e9eec3eba"
125+dependencies = [
126+ "unicode-ident",
127+]
128+
129+[[package]]
130+name = "quote"
131+version = "1.0.36"
132+source = "registry+https://github.com/rust-lang/crates.io-index"
133+checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7"
134+dependencies = [
135+ "proc-macro2",
136+]
137+
138+[[package]]
139+name = "rmptui"
140+version = "0.1.0"
141+dependencies = [
142+ "clap",
143+ "mpd",
144+ "rust_fzf",
145+]
146+
147+[[package]]
148+name = "rust_fzf"
149+version = "0.3.1"
150+source = "registry+https://github.com/rust-lang/crates.io-index"
151+checksum = "76a94b9c6a9880356cc6de038a52397509f8ac86a18c30d76da904b08fec2cb1"
152+
153+[[package]]
154+name = "strsim"
155+version = "0.11.1"
156+source = "registry+https://github.com/rust-lang/crates.io-index"
157+checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f"
158+
159+[[package]]
160+name = "syn"
161+version = "2.0.60"
162+source = "registry+https://github.com/rust-lang/crates.io-index"
163+checksum = "909518bc7b1c9b779f1bbf07f2929d35af9f0f37e47c6e9ef7f9dddc1e1821f3"
164+dependencies = [
165+ "proc-macro2",
166+ "quote",
167+ "unicode-ident",
168+]
169+
170+[[package]]
171+name = "unicode-ident"
172+version = "1.0.12"
173+source = "registry+https://github.com/rust-lang/crates.io-index"
174+checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b"
175+
176+[[package]]
177+name = "utf8parse"
178+version = "0.2.1"
179+source = "registry+https://github.com/rust-lang/crates.io-index"
180+checksum = "711b9620af191e0cdc7468a8d14e709c3dcdb115b36f838e601583af800a370a"
181+
182+[[package]]
183+name = "windows-sys"
184+version = "0.52.0"
185+source = "registry+https://github.com/rust-lang/crates.io-index"
186+checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d"
187+dependencies = [
188+ "windows-targets",
189+]
190+
191+[[package]]
192+name = "windows-targets"
193+version = "0.52.5"
194+source = "registry+https://github.com/rust-lang/crates.io-index"
195+checksum = "6f0713a46559409d202e70e28227288446bf7841d3211583a4b53e3f6d96e7eb"
196+dependencies = [
197+ "windows_aarch64_gnullvm",
198+ "windows_aarch64_msvc",
199+ "windows_i686_gnu",
200+ "windows_i686_gnullvm",
201+ "windows_i686_msvc",
202+ "windows_x86_64_gnu",
203+ "windows_x86_64_gnullvm",
204+ "windows_x86_64_msvc",
205+]
206+
207+[[package]]
208+name = "windows_aarch64_gnullvm"
209+version = "0.52.5"
210+source = "registry+https://github.com/rust-lang/crates.io-index"
211+checksum = "7088eed71e8b8dda258ecc8bac5fb1153c5cffaf2578fc8ff5d61e23578d3263"
212+
213+[[package]]
214+name = "windows_aarch64_msvc"
215+version = "0.52.5"
216+source = "registry+https://github.com/rust-lang/crates.io-index"
217+checksum = "9985fd1504e250c615ca5f281c3f7a6da76213ebd5ccc9561496568a2752afb6"
218+
219+[[package]]
220+name = "windows_i686_gnu"
221+version = "0.52.5"
222+source = "registry+https://github.com/rust-lang/crates.io-index"
223+checksum = "88ba073cf16d5372720ec942a8ccbf61626074c6d4dd2e745299726ce8b89670"
224+
225+[[package]]
226+name = "windows_i686_gnullvm"
227+version = "0.52.5"
228+source = "registry+https://github.com/rust-lang/crates.io-index"
229+checksum = "87f4261229030a858f36b459e748ae97545d6f1ec60e5e0d6a3d32e0dc232ee9"
230+
231+[[package]]
232+name = "windows_i686_msvc"
233+version = "0.52.5"
234+source = "registry+https://github.com/rust-lang/crates.io-index"
235+checksum = "db3c2bf3d13d5b658be73463284eaf12830ac9a26a90c717b7f771dfe97487bf"
236+
237+[[package]]
238+name = "windows_x86_64_gnu"
239+version = "0.52.5"
240+source = "registry+https://github.com/rust-lang/crates.io-index"
241+checksum = "4e4246f76bdeff09eb48875a0fd3e2af6aada79d409d33011886d3e1581517d9"
242+
243+[[package]]
244+name = "windows_x86_64_gnullvm"
245+version = "0.52.5"
246+source = "registry+https://github.com/rust-lang/crates.io-index"
247+checksum = "852298e482cd67c356ddd9570386e2862b5673c85bd5f88df9ab6802b334c596"
248+
249+[[package]]
250+name = "windows_x86_64_msvc"
251+version = "0.52.5"
252+source = "registry+https://github.com/rust-lang/crates.io-index"
253+checksum = "bec47e5bfd1bff0eeaf6d8b485cc1074891a197ab4225d504cb7a1ab88b02bf0"
A Cargo.toml View
@@ -0,0 +1,11 @@
1+[package]
2+name = "rmptui"
3+version = "0.1.0"
4+edition = "2021"
5+
6+# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
7+
8+[dependencies]
9+mpd = "0.1.0"
10+clap = { version = "4.0.29", features = ["derive"] }
11+rust_fzf = "0.3.1"
M README.md View

Mode 100644 → 100755

[No content changes]

A src/connection.rs View
@@ -0,0 +1,92 @@
1+use mpd::song::Song;
2+use mpd::Client;
3+
4+pub struct Connection {
5+ pub conn: Client,
6+}
7+
8+impl Connection {
9+ pub fn new(addrs: &str) -> Result<Self, mpd::error::Error> {
10+ let conn = Client::connect(addrs)?;
11+ Ok(Self { conn })
12+ }
13+
14+ pub fn play_fzf(&mut self) {
15+ let mut ss: Vec<String> = Vec::new();
16+ self.get_file_tree_into_vec(&mut ss, ".", ".");
17+
18+ let choice: usize;
19+ let fzf_choice = rust_fzf::select(ss.clone(), Vec::new()).unwrap();
20+ if let Some(index) = ss.iter().position(|s| s == fzf_choice.get(0).unwrap()) {
21+ choice = index;
22+ } else {
23+ return;
24+ }
25+
26+ let song = self.get_song(ss.get(choice).unwrap());
27+
28+ if self.conn.queue().unwrap().is_empty() {
29+ self.push(song);
30+ self.conn.play().unwrap();
31+ } else {
32+ self.push(song);
33+ self.conn.next().unwrap();
34+ }
35+ }
36+
37+ fn get_file_tree_into_vec(&mut self, vec: &mut Vec<String>, path: &str, dir_append: &str) {
38+ let songs = self.conn.listfiles(path).unwrap_or_default();
39+ for (i, s) in songs {
40+ // Output of listfiles contains the last-modified thing, we dont want that
41+ if i != "Last-Modified" {
42+ if i == "directory" {
43+ self.get_file_tree_into_vec(vec, &s, &s);
44+ } else {
45+ // We parse the string as float because the output of listfiles contains some random numbers, we dont want that
46+ if !s.parse::<f32>().is_ok() {
47+ let mut sam: String = String::new();
48+ sam.push_str(dir_append);
49+ sam.push_str(r"/");
50+ sam.push_str(s.as_str());
51+ vec.push(sam);
52+ }
53+ }
54+ }
55+ }
56+ }
57+
58+ fn push(&mut self, song: Song) {
59+ self.conn.push(song).unwrap();
60+
61+ }
62+
63+ fn get_song(&self, filename: &str) -> Song {
64+ Song {
65+ file: filename.to_string(),
66+ artist: None,
67+ title: None,
68+ duration: None,
69+ last_mod: None,
70+ name: None,
71+ place: None,
72+ range: None,
73+ tags: vec![("".to_string(), "".to_string())],
74+ }
75+ }
76+
77+ pub fn status(&mut self) {
78+ let current_song = self.conn.currentsong();
79+ let status = self.conn.status().unwrap();
80+
81+ if current_song.is_ok() {
82+ let song = current_song.unwrap();
83+ if let Some(s) = song {
84+ println!("{} - {}", s.artist.unwrap(), s.title.unwrap());
85+ }
86+ }
87+ println!(
88+ "volume: {}\trepeat: {}\trandom: {}\tsingle: {}\tconsume: {}",
89+ status.volume, status.repeat, status.random, status.single, status.consume
90+ );
91+ }
92+}
A src/main.rs View
@@ -0,0 +1,34 @@
1+mod connection;
2+use clap::Parser;
3+use connection::Connection;
4+
5+#[derive(Parser, Debug)]
6+#[command(version, about, long_about = None)]
7+struct Args {
8+ /// Ignore case in search
9+ #[arg(short, long, default_value = "false")]
10+ pub pause: bool,
11+
12+ #[arg(short, long, default_value = "false")]
13+ pub toggle_pause: bool,
14+
15+ #[arg(short, long, default_value = "false")]
16+ pub show_status: bool,
17+
18+ #[arg(short, long, default_value = "false")]
19+ pub fzf_select: bool,
20+}
21+
22+fn main() -> Result<(), Box<dyn std::error::Error>> {
23+ let args = Args::parse();
24+ let mut conn = Connection::new("127.0.0.1:6600")?;
25+ if args.show_status {
26+ conn.status();
27+ }
28+
29+ if args.fzf_select {
30+ conn.play_fzf()
31+ }
32+
33+ Ok(())
34+}