Skip to content

Commit b785e1e

Browse files
committed
added prettier bytes
1 parent 5a5773b commit b785e1e

File tree

3 files changed

+50
-19
lines changed

3 files changed

+50
-19
lines changed

Cargo.lock

Lines changed: 46 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,4 @@ edition = "2018"
1010
termion = "*"
1111
chrono = "*"
1212
users = "*"
13+
pretty-bytes = "*"

src/main.rs

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ use std::os::unix::fs::MetadataExt;
33
use std::{env, fs, io};
44
use termion::color;
55
use users::{get_current_uid, get_user_by_uid};
6+
extern crate pretty_bytes;
7+
use pretty_bytes::converter::convert;
68

79
fn main() -> io::Result<()> {
810
let args: Vec<String> = env::args().collect();
@@ -58,25 +60,7 @@ fn main() -> io::Result<()> {
5860
print!(" ")
5961
}
6062
print!("{}", color::Fg(color::Green));
61-
if fs::metadata(&e)?.size() > 1000 {
62-
let mut first = fs::metadata(&e)?.size() / 1000;
63-
let mut second = fs::metadata(&e)?.size() % 1000;
64-
if second + 1000 > 500 {
65-
first += 1;
66-
second = 0;
67-
}
68-
69-
print!(" {}.{}", first, second);
70-
print!("{}", color::Fg(color::Yellow));
71-
print!("k");
72-
} else {
73-
let res = format!(" {:?}", fs::metadata(&e)?.size());
74-
let length = 5 - res.len();
75-
for _ in 0..length {
76-
print!(" ");
77-
}
78-
print!("{}", res);
79-
}
63+
print!(" {}", convert(fs::metadata(&e)?.size() as f64));
8064

8165
if let Ok(time) = e.metadata()?.created() {
8266
print!("{}", color::Fg(color::Blue));

0 commit comments

Comments
 (0)