From d24727d301421dec5ec8205c4f735c3654aa4913 Mon Sep 17 00:00:00 2001 From: Lux Aliaga Date: Sun, 18 Sep 2022 00:35:50 -0300 Subject: [PATCH] inv: Prevent non-files from displaying file size Maybe for folders I could later add a folder size but the method I'm using to calculate file sizes doesn't work with folders, so yeah. --- src/inv.rs | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/inv.rs b/src/inv.rs index 909c63a..8044637 100644 --- a/src/inv.rs +++ b/src/inv.rs @@ -117,7 +117,7 @@ pub fn list(slot: &str, dir: &str) { let file = file.unwrap().path(); println!( - " - [{}] {} ({})", + " - [{}] {}{}", if file.clone().is_dir() { format!("D").blue() } else if file.clone().is_symlink() { @@ -131,10 +131,14 @@ pub fn list(slot: &str, dir: &str) { .to_os_string() .into_string() .unwrap(), - format!( - "{}B", - SizeFormatterBinary::new(file.clone().metadata().unwrap().len()) - ) + if file.clone().is_file() { + format!( + " ({}B)", + SizeFormatterBinary::new(file.clone().metadata().unwrap().len()) + ) + } else { + format!("") + } ); } } @@ -182,6 +186,6 @@ fn create_slots() { println!( "🎉 {}", - format!("Vento has been succesfully initialized!").green() + format!("Vento has been succesfully initialized!").green() ); }