Krolyxon
Commit 3578eae

rmptui3578eae

remove this absolute brainfuck of a function, what the fuck

Author
krolxon
Date
2024-04-22 14:46 +0530
Parent
bc0348e
Commit
3578eae01a8d5a537cff3ad47105bc340b081fe7

+6 −23

1 file changed

  1. M src/connection.rs +6 −23
M src/connection.rs View
@@ -10,8 +10,12 @@ pub struct Connection {
1010 impl Connection {
1111 pub fn new(addrs: &str) -> Result<Self, mpd::error::Error> {
1212 let mut conn = Client::connect(addrs)?;
13− let mut songs_filenames: Vec<String> = Vec::new();
14− get_file_tree_into_vec(&mut conn, &mut songs_filenames, ".", ".");
13+ let songs_filenames: Vec<String> = conn
14+ .listall()
15+ .unwrap()
16+ .iter()
17+ .map(|x| x.clone().file)
18+ .collect();
1519
1620 Ok(Self {
1721 conn,
@@ -99,27 +103,6 @@ impl Connection {
99103 }
100104 }
101105
102−fn get_file_tree_into_vec(conn: &mut Client, vec: &mut Vec<String>, path: &str, dir_append: &str) {
103− let songs = conn.listfiles(path).unwrap_or_default();
104− for (i, s) in songs {
105− // Output of listfiles contains the last-modified thing, we dont want that
106− if i != "Last-Modified" {
107− if i == "directory" {
108− get_file_tree_into_vec(conn, vec, &s, &s);
109− } else {
110− // We parse the string as float because the output of listfiles contains some random numbers, we dont want that
111− if !s.parse::<f32>().is_ok() {
112− let mut sam: String = String::new();
113− sam.push_str(dir_append);
114− sam.push_str(r"/");
115− sam.push_str(s.as_str());
116− vec.push(sam);
117− }
118− }
119− }
120− }
121−}
122−
123106 fn get_choice_index(ss: &Vec<String>, selection: &str) -> usize {
124107 let mut choice: usize = 0;
125108 if let Some(index) = ss.iter().position(|s| s == selection) {