1use colored::Colorize;
2
3pub struct ReadDirOptions {
4 pub dotfiles: bool,
6
7 pub implied: bool,
9
10 pub sort: bool,
12
13 pub reverse: bool,
15}
16
17impl ReadDirOptions {
18 pub fn new() -> Self {
19 Self {
20 dotfiles: false,
21 implied: false,
22 sort: true,
23 reverse: false,
24 }
25 }
26}
27
28pub fn read_dir_to_string(options: ReadDirOptions) -> String {
29 let mut paths: Vec<String> = std::fs::read_dir("./")
30 .unwrap()
31 .map(|path| path.unwrap().file_name().into_string().unwrap())
32 .collect();
33
34 if options.implied {
35 paths.push(String::from("."));
36 paths.push(String::from(".."));
37 }
38
39 if !options.dotfiles{
40 paths = paths
41 .into_iter()
42 .filter(|path| path.as_bytes()[0] != b'.')
43 .collect();
44 }
45
46 if options.sort {
47 paths.sort();
48 }
49
50 if options.reverse {
51 paths.reverse();
52 }
53
54 for path in &mut paths {
56 if std::path::Path::new(&path).is_dir() {
57 *path = path.bold().blue().to_string();
58 }
59 }
60
61 paths.join(" ")
62}