Skip to content

Commit 0564a63

Browse files
committed
made file sizes work better
1 parent c3e1f0e commit 0564a63

File tree

3 files changed

+22
-7
lines changed

3 files changed

+22
-7
lines changed

Cargo.lock

Lines changed: 8 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "natls"
3-
version = "1.2.8"
3+
version = "1.2.9"
44
authors = ["Will Lane <[email protected]>"]
55
description = "nat - the 'ls' replacement you never knew you needed"
66
license = "MIT"
@@ -16,6 +16,7 @@ ansi_term = "0.12"
1616
structopt = "0.3"
1717
libc = "0.2"
1818
filetime = "0.1"
19+
humansize = "1.1.0"
1920

2021
[profile.dev]
2122
opt-level = 0

src/main.rs

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
#![allow(clippy::collapsible_if)]
22
extern crate libc;
33
extern crate pretty_bytes;
4-
54
use ansi_term::Style;
65
use chrono::prelude::*;
76
use filetime::FileTime;
7+
use humansize::{file_size_opts as options, FileSize};
88
use libc::{S_IRGRP, S_IROTH, S_IRUSR, S_IWGRP, S_IWOTH, S_IWUSR, S_IXGRP, S_IXOTH, S_IXUSR};
99
use pretty_bytes::converter::convert;
1010
use std::{
@@ -229,7 +229,12 @@ pub fn file_size(
229229
e: &&std::path::PathBuf,
230230
) -> Result<(), Box<dyn std::error::Error>> {
231231
if size_count > 4 {
232-
for _ in 0..(size_count - convert(fs::symlink_metadata(&e)?.size() as f64).len()) {
232+
for _ in 0..(size_count
233+
- (fs::symlink_metadata(&e)?.size())
234+
.file_size(options::CONVENTIONAL)
235+
.unwrap()
236+
.len())
237+
{
233238
print!(" ");
234239
}
235240
}
@@ -238,9 +243,11 @@ pub fn file_size(
238243
}
239244
print!(
240245
"{} ",
241-
Style::new()
242-
.bold()
243-
.paint(convert(fs::symlink_metadata(&e)?.size() as f64))
246+
Style::new().bold().paint(
247+
(fs::symlink_metadata(&e)?.size())
248+
.file_size(options::CONVENTIONAL)
249+
.unwrap()
250+
)
244251
);
245252
Ok(())
246253
}

0 commit comments

Comments
 (0)