Skip to content

Commit cc5c128

Browse files
committed
updated code formatting
1 parent b9e7504 commit cc5c128

File tree

1 file changed

+31
-86
lines changed

1 file changed

+31
-86
lines changed

src/main.rs

+31-86
Original file line numberDiff line numberDiff line change
@@ -58,92 +58,37 @@ impl PathType {
5858

5959
fn get_letter_for_type(&self) -> String {
6060
match self {
61-
Self::Dir => String::from(format!(
62-
"{}d{}{}",
63-
self.get_color_for_type(),
64-
termion::color::Fg(termion::color::Reset),
65-
termion::color::Bg(termion::color::Reset)
66-
)),
67-
Self::Symlink => String::from(format!(
68-
"{}l{}{}",
69-
self.get_color_for_type(),
70-
termion::color::Fg(termion::color::Reset),
71-
termion::color::Bg(termion::color::Reset)
72-
)),
73-
Self::Pipe => String::from(format!(
74-
"{}|{}{}",
75-
self.get_color_for_type(),
76-
termion::color::Fg(termion::color::Reset),
77-
termion::color::Bg(termion::color::Reset)
78-
)),
79-
Self::CharD => String::from(format!(
80-
"{}c{}{}",
81-
self.get_color_for_type(),
82-
termion::color::Fg(termion::color::Reset),
83-
termion::color::Bg(termion::color::Reset)
84-
)),
85-
Self::BlockD => String::from(format!(
86-
"{}b{}{}",
87-
self.get_color_for_type(),
88-
termion::color::Fg(termion::color::Reset),
89-
termion::color::Bg(termion::color::Reset)
90-
)),
91-
Self::Socket => String::from(format!(
92-
"{}s{}{}",
93-
self.get_color_for_type(),
94-
termion::color::Fg(termion::color::Reset),
95-
termion::color::Bg(termion::color::Reset)
96-
)),
97-
_ => String::from(format!(
98-
"{}.{}{}",
99-
self.get_color_for_type(),
100-
termion::color::Fg(termion::color::Reset),
101-
termion::color::Bg(termion::color::Reset)
102-
)),
61+
Self::Dir => format!( "{}d{}{}", self.get_color_for_type(), termion::color::Fg(termion::color::Reset), termion::color::Bg(termion::color::Reset) ),
62+
Self::Symlink => format!( "{}l{}{}", self.get_color_for_type(), termion::color::Fg(termion::color::Reset), termion::color::Bg(termion::color::Reset) ),
63+
Self::Pipe => format!( "{}|{}{}", self.get_color_for_type(), termion::color::Fg(termion::color::Reset), termion::color::Bg(termion::color::Reset) ),
64+
Self::CharD => format!( "{}c{}{}", self.get_color_for_type(), termion::color::Fg(termion::color::Reset), termion::color::Bg(termion::color::Reset) ),
65+
Self::BlockD => format!( "{}b{}{}", self.get_color_for_type(), termion::color::Fg(termion::color::Reset), termion::color::Bg(termion::color::Reset) ),
66+
Self::Socket => format!( "{}s{}{}", self.get_color_for_type(), termion::color::Fg(termion::color::Reset), termion::color::Bg(termion::color::Reset) ),
67+
_ => format!( "{}.{}{}", self.get_color_for_type(), termion::color::Fg(termion::color::Reset), termion::color::Bg(termion::color::Reset) ),
10368
}
10469
}
10570

10671
fn get_color_for_type(&self) -> String {
10772
match self {
108-
Self::Dir => format!("{}", termion::color::Fg(termion::color::LightBlue)),
109-
Self::Symlink => format!("{}", termion::color::Fg(termion::color::LightMagenta)),
110-
Self::Path => format!("{}", termion::color::Fg(termion::color::White)),
111-
Self::Pipe => format!("{}", termion::color::Fg(termion::color::Yellow)),
112-
Self::CharD => format!(
113-
"{}{}",
114-
termion::color::Bg(termion::color::Yellow),
115-
termion::color::Fg(termion::color::LightBlue)
116-
),
117-
Self::BlockD => format!("{}", termion::color::Fg(termion::color::LightGreen)),
118-
Self::Socket => format!("{}", termion::color::Fg(termion::color::LightRed)),
73+
Self::Dir => format!("{}", termion::color::Fg(termion::color::LightBlue)),
74+
Self::Symlink => format!("{}", termion::color::Fg(termion::color::LightMagenta)),
75+
Self::Path => format!("{}", termion::color::Fg(termion::color::White)),
76+
Self::Pipe => format!("{}", termion::color::Fg(termion::color::Yellow)),
77+
Self::CharD => format!( "{}{}", termion::color::Bg(termion::color::Yellow), termion::color::Fg(termion::color::LightBlue) ),
78+
Self::BlockD => format!("{}", termion::color::Fg(termion::color::LightGreen)),
79+
Self::Socket => format!("{}", termion::color::Fg(termion::color::LightRed)),
11980
}
12081
}
12182

12283
fn get_text_traits_for_type(&self, name: &str, file: &std::path::PathBuf) -> String {
12384
match self {
124-
Self::Dir => text_effects::bold(&format!(
125-
"{}{}/",
126-
name,
127-
termion::color::Fg(termion::color::White)
128-
)),
129-
Self::Symlink => text_effects::italic(&format!(
130-
"{} -> {}",
131-
name,
132-
std::fs::read_link(file).unwrap().display().to_string()
133-
)),
134-
Self::Path => text_effects::bold(name),
135-
Self::Pipe => text_effects::bold(&format!(
136-
"{}{}|",
137-
name,
138-
termion::color::Fg(termion::color::White)
139-
)),
140-
Self::CharD => text_effects::bold(name),
141-
Self::BlockD => text_effects::bold(name),
142-
Self::Socket => text_effects::bold(&format!(
143-
"{}{}=",
144-
name,
145-
termion::color::Fg(termion::color::White)
146-
)),
85+
Self::Dir => text_effects::bold(&format!( "{}{}/", name, termion::color::Fg(termion::color::White) )),
86+
Self::Symlink => text_effects::italic(&format!( "{} -> {}", name, std::fs::read_link(file).unwrap().display().to_string() )),
87+
Self::Path => text_effects::bold(name),
88+
Self::Pipe => text_effects::bold(&format!( "{}{}|", name, termion::color::Fg(termion::color::White) )),
89+
Self::CharD => text_effects::bold(name),
90+
Self::BlockD => text_effects::bold(name),
91+
Self::Socket => text_effects::bold(&format!( "{}{}=", name, termion::color::Fg(termion::color::White) )),
14792
}
14893
}
14994
}
@@ -308,17 +253,17 @@ impl Directory {
308253
input::Cli::from_args().modified,
309254
input::Cli::from_args().size,
310255
]) {
311-
DirSortType::Name => self.self_name_sort(),
312-
DirSortType::Created => self.self_create_sort(),
256+
DirSortType::Name => self.self_name_sort(),
257+
DirSortType::Created => self.self_create_sort(),
313258
DirSortType::Modified => self.self_modified_sort(),
314-
DirSortType::Size => self.self_size_sort(),
315-
DirSortType::Not => (),
259+
DirSortType::Size => self.self_size_sort(),
260+
DirSortType::Not => (),
316261
}
317262
}
318263

319264
fn sort(&mut self) {
320265
match input::Cli::from_args().gdf {
321-
true => self.sort_directory_then_path(),
266+
true => self.sort_directory_then_path(),
322267
false => self.sort_paths(),
323268
}
324269
}
@@ -343,15 +288,15 @@ impl Directory {
343288
let ghold = self.paths[p].group.clone();
344289
let uhold = self.paths[p].user.clone();
345290
let shold = self.paths[p].size.clone();
346-
let mut gwidth = String::from("");
291+
let mut gwidth = String::new();
347292
for _ in 0..(gs - ghold.len()) {
348293
gwidth.push(' ')
349294
}
350-
let mut uwidth = String::from("");
295+
let mut uwidth = String::new();
351296
for _ in 0..(us - uhold.len()) {
352297
uwidth.push(' ')
353298
}
354-
let mut swidth = String::from("");
299+
let mut swidth = String::new();
355300
for _ in 0..(ss - shold.len()) {
356301
swidth.push(' ')
357302
}
@@ -478,9 +423,9 @@ impl std::fmt::Display for Directory {
478423
}
479424

480425
fn main() {
481-
let mut dir = Directory::new(input::Cli::from_args().dir).unwrap();
426+
let mut dir = Directory::new(input::Cli::from_args().dir).expect("Failed to run natls");
482427
dir.setup();
483-
println!("{}", dir)
428+
println!("{}", dir);
484429
}
485430

486431
#[cfg(test)]

0 commit comments

Comments
 (0)