inv: Add file size to inventory list

This commit also improves formatting in the inventory list.
This commit is contained in:
Lux Aliaga 2022-09-17 18:33:40 -03:00
parent 28bed7faff
commit 6c10953e88
Signed by: lux
GPG Key ID: B56C805968637437
3 changed files with 111 additions and 10 deletions

96
Cargo.lock generated
View File

@ -19,6 +19,12 @@ dependencies = [
"winapi",
]
[[package]]
name = "autocfg"
version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa"
[[package]]
name = "bitflags"
version = "1.3.2"
@ -68,6 +74,15 @@ version = "1.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2022715d62ab30faffd124d40b76f4134a550a87792276512b18d63272333394"
[[package]]
name = "generic-array"
version = "0.12.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ffdf9f34f1447443d37393cc6c2b8313aebddcd96906caf34e54c68d8e57d7bd"
dependencies = [
"typenum",
]
[[package]]
name = "getrandom"
version = "0.2.7"
@ -100,6 +115,70 @@ version = "0.2.132"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8371e4e5341c3a96db127eb2465ac681ced4c433e01dd0e938adbef26ba93ba5"
[[package]]
name = "num"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b8536030f9fea7127f841b45bb6243b27255787fb4eb83958aa1ef9d2fdc0c36"
dependencies = [
"num-complex",
"num-integer",
"num-iter",
"num-rational",
"num-traits",
]
[[package]]
name = "num-complex"
version = "0.2.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b6b19411a9719e753aff12e5187b74d60d3dc449ec3f4dc21e3989c3f554bc95"
dependencies = [
"autocfg",
"num-traits",
]
[[package]]
name = "num-integer"
version = "0.1.45"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "225d3389fb3509a24c93f5c29eb6bde2586b98d9f016636dff58d7c6f7569cd9"
dependencies = [
"autocfg",
"num-traits",
]
[[package]]
name = "num-iter"
version = "0.1.43"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7d03e6c028c5dc5cac6e2dec0efda81fc887605bb3d884578bb6d6bf7514e252"
dependencies = [
"autocfg",
"num-integer",
"num-traits",
]
[[package]]
name = "num-rational"
version = "0.2.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5c000134b5dbf44adc5cb772486d335293351644b801551abe8f75c84cfa4aef"
dependencies = [
"autocfg",
"num-integer",
"num-traits",
]
[[package]]
name = "num-traits"
version = "0.2.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "578ede34cf02f8924ab9447f50c28075b4d3e5b269972345e7e0372b38c6cdcd"
dependencies = [
"autocfg",
]
[[package]]
name = "proc-macro2"
version = "1.0.43"
@ -138,6 +217,16 @@ dependencies = [
"thiserror",
]
[[package]]
name = "size_format"
version = "1.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6ed5f6ab2122c6dec69dca18c72fa4590a27e581ad20d44960fe74c032a0b23b"
dependencies = [
"generic-array",
"num",
]
[[package]]
name = "syn"
version = "1.0.99"
@ -169,6 +258,12 @@ dependencies = [
"syn",
]
[[package]]
name = "typenum"
version = "1.15.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dcf81ac59edc17cc8697ff311e8f5ef2d99fcbd9817b34cec66f90b6c3dfd987"
[[package]]
name = "unicode-ident"
version = "1.0.3"
@ -183,6 +278,7 @@ dependencies = [
"colored",
"dirs",
"fs_extra",
"size_format",
]
[[package]]

View File

@ -10,3 +10,4 @@ dirs = "4.0.0"
colored = "2.0.0"
fs_extra = "1.2.0"
anyhow = "1.0.65"
size_format = "1.0.2"

View File

@ -19,6 +19,7 @@
use super::common;
use colored::Colorize;
use size_format::SizeFormatterBinary;
use std::io::{self, Write};
use std::path::{Path, PathBuf};
use std::{fs, process};
@ -73,20 +74,24 @@ pub fn list(slot: &str) {
let file = file.unwrap().path();
println!(
" - {} ({})",
" - [{}] {} ({})",
if file.clone().is_dir() {
format!("D").blue()
} else if file.clone().is_symlink() {
format!("S").yellow()
} else {
format!("F").green()
},
file.clone()
.file_name()
.unwrap()
.to_os_string()
.into_string()
.unwrap(),
if file.clone().is_dir() {
format!("dir").blue()
} else if file.clone().is_symlink() {
format!("symlink").yellow()
} else {
format!("file").green()
}
format!(
"{}B",
SizeFormatterBinary::new(file.clone().metadata().unwrap().len())
)
);
}
} else {
@ -132,7 +137,6 @@ fn create_slots() {
.expect("❌ Vento was unable to initalize. Do you have the correct permissions?");
println!(
"🎉 {}",
format!("Vento has been succesfully initialized!").green()
"🎉 {}", format!("Vento has been succesfully initialized!").green()
);
}