Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d3fa946

Browse files
refactor: colored path printing; fix size column format
1 parent 6a636d5 commit d3fa946

1 file changed

Lines changed: 19 additions & 24 deletions

File tree

src/aggregate.rs

Lines changed: 19 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use crate::{crossdev, InodeFilter, WalkOptions, WalkResult};
22
use anyhow::Result;
33
use filesize::PathExt;
44
use owo_colors::{AnsiColors as Color, OwoColorize};
5-
use std::{borrow::Cow, io, path::Path};
5+
use std::{io, path::Path};
66
use std::{
77
sync::{
88
atomic::{AtomicBool, Ordering},
@@ -201,29 +201,24 @@ fn output_colored_path(
201201
num_errors: u64,
202202
path_color: Option<Color>,
203203
) -> std::result::Result<(), io::Error> {
204-
writeln!(
205-
out,
206-
"{:>byte_column_width$} {}{}",
207-
options.byte_format.display(num_bytes).green(),
208-
{
209-
let path = path.as_ref().display();
210-
match path_color {
211-
Some(color) => path.color(color),
212-
None => path.color(Color::Default),
213-
}
214-
.to_string()
215-
},
216-
if num_errors == 0 {
217-
Cow::Borrowed("")
218-
} else {
219-
Cow::Owned(format!(
220-
" <{} IO Error{}>",
221-
num_errors,
222-
if num_errors > 1 { "s" } else { "" }
223-
))
224-
},
225-
byte_column_width = options.byte_format.width()
226-
)
204+
let size = options.byte_format.display(num_bytes).to_string();
205+
let size = size.green();
206+
let size_width = options.byte_format.width();
207+
208+
let path = path.as_ref().display();
209+
210+
let errors = if let 0 = num_errors {
211+
String::new()
212+
} else {
213+
let s = if num_errors > 1 { "s" } else { "" };
214+
format!(" <{num_errors} IO Error{s}>")
215+
};
216+
217+
if let Some(color) = path_color {
218+
writeln!(out, "{size:>size_width$} {}{errors}", path.color(color),)
219+
} else {
220+
writeln!(out, "{size:>size_width$} {path}{errors}",)
221+
}
227222
}
228223

229224
/// Statistics obtained during a filesystem walk

0 commit comments

Comments
 (0)