Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
Byron committed Sep 19, 2022
1 parent 44e19ee commit a734efb
Showing 1 changed file with 9 additions and 14 deletions.
23 changes: 9 additions & 14 deletions src/aggregate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,11 +186,7 @@ pub fn aggregate(
}

fn path_color_of(path: impl AsRef<Path>) -> Option<Color> {
if path.as_ref().is_file() {
None
} else {
Some(Color::Cyan)
}
(!path.as_ref().is_file()).then(|| Color::Cyan)
}

fn output_colored_path(
Expand All @@ -204,20 +200,19 @@ fn output_colored_path(
let size = options.byte_format.display(num_bytes).to_string();
let size = size.green();
let size_width = options.byte_format.width();

let path = path.as_ref().display();

let errors = if let 0 = num_errors {
String::new()
} else {
let s = if num_errors > 1 { "s" } else { "" };
format!(" <{num_errors} IO Error{s}>")
};
let errors = (num_errors != 0)
.then(|| {
let plural_s = if num_errors > 1 { "s" } else { "" };
format!(" <{num_errors} IO Error{plural_s}>")
})
.unwrap_or_default();

if let Some(color) = path_color {
writeln!(out, "{size:>size_width$} {}{errors}", path.color(color),)
writeln!(out, "{size:>size_width$} {}{errors}", path.color(color))
} else {
writeln!(out, "{size:>size_width$} {path}{errors}",)
writeln!(out, "{size:>size_width$} {path}{errors}")
}
}

Expand Down

0 comments on commit a734efb

Please sign in to comment.