diff options
author | Sebastian Thiel <sthiel@thoughtworks.com> | 2019-06-01 14:12:26 +0530 |
---|---|---|
committer | Sebastian Thiel <sthiel@thoughtworks.com> | 2019-06-01 14:12:26 +0530 |
commit | e7da7843ad7894a3560b4d70076a74798404da94 (patch) | |
tree | ea657e381c22a049c54d38b4edff55796451c429 | |
parent | 9ba5a348c67a898abb0ae648e686da48649a33df (diff) |
Nicer formatting of numbers
-rw-r--r-- | src/aggregate.rs | 2 | ||||
-rw-r--r-- | src/common.rs | 18 | ||||
-rw-r--r-- | tests/snapshots/failure-no-arguments-multiple-input-paths-some-not-existing | 12 | ||||
-rw-r--r-- | tests/snapshots/success-bytes-binary | 2 | ||||
-rw-r--r-- | tests/snapshots/success-bytes-only | 2 | ||||
-rw-r--r-- | tests/snapshots/success-no-arguments | 2 | ||||
-rw-r--r-- | tests/snapshots/success-no-arguments-multiple-input-paths | 12 | ||||
-rw-r--r-- | tests/snapshots/success-no-arguments-multiple-input-paths-no-total | 10 |
8 files changed, 37 insertions, 23 deletions
diff --git a/src/aggregate.rs b/src/aggregate.rs index 6e49a5a..62b8acc 100644 --- a/src/aggregate.rs +++ b/src/aggregate.rs @@ -60,7 +60,7 @@ fn write_path( ) -> Result<(), io::Error> { writeln!( out, - "{:8}\t{}{}", + "{:>10}\t{}{}", options.format_bytes(num_bytes), path.as_ref().display(), if num_errors == 0 { diff --git a/src/common.rs b/src/common.rs index 91a24f1..e17a712 100644 --- a/src/common.rs +++ b/src/common.rs @@ -26,9 +26,23 @@ impl WalkOptions { Binary => true, Metric => false, }; - Byte::from_bytes(b as u128) + let b = Byte::from_bytes(b as u128) .get_appropriate_unit(binary) - .format(2) + .format(2); + let mut splits = b.split(' '); + match (splits.next(), splits.next()) { + (Some(bytes), Some(unit)) => format!( + "{:>8} {:>unit_width$}", + bytes, + unit, + unit_width = match self.format { + Binary => 3, + Metric => 2, + _ => 2, + } + ), + _ => b, + } } pub fn iter_from_path(&self, path: &Path, sort: Sorting) -> WalkDir { diff --git a/tests/snapshots/failure-no-arguments-multiple-input-paths-some-not-existing b/tests/snapshots/failure-no-arguments-multiple-input-paths-some-not-existing index c685916..4c9d9a2 100644 --- a/tests/snapshots/failure-no-arguments-multiple-input-paths-some-not-existing +++ b/tests/snapshots/failure-no-arguments-multiple-input-paths-some-not-existing @@ -1,6 +1,6 @@ -1.26 MB . -1.26 MB . -0.00 B foo <1 IO Error(s)> -0.00 B bar <1 IO Error(s)> -0.00 B baz <1 IO Error(s)> -2.52 MB total <3 IO Error(s)>
\ No newline at end of file + 1.26 MB . + 1.26 MB . + 0.00 B foo <1 IO Error(s)> + 0.00 B bar <1 IO Error(s)> + 0.00 B baz <1 IO Error(s)> + 2.52 MB total <3 IO Error(s)>
\ No newline at end of file diff --git a/tests/snapshots/success-bytes-binary b/tests/snapshots/success-bytes-binary index 59210ca..dc4db03 100644 --- a/tests/snapshots/success-bytes-binary +++ b/tests/snapshots/success-bytes-binary @@ -1 +1 @@ -1.20 MiB .
\ No newline at end of file + 1.20 MiB .
\ No newline at end of file diff --git a/tests/snapshots/success-bytes-only b/tests/snapshots/success-bytes-only index e0c2326..85a7d8a 100644 --- a/tests/snapshots/success-bytes-only +++ b/tests/snapshots/success-bytes-only @@ -1 +1 @@ -1258947 b .
\ No newline at end of file + 1258947 b .
\ No newline at end of file diff --git a/tests/snapshots/success-no-arguments b/tests/snapshots/success-no-arguments index fa1c9b7..51714b5 100644 --- a/tests/snapshots/success-no-arguments +++ b/tests/snapshots/success-no-arguments @@ -1 +1 @@ -1.26 MB .
\ No newline at end of file + 1.26 MB .
\ No newline at end of file diff --git a/tests/snapshots/success-no-arguments-multiple-input-paths b/tests/snapshots/success-no-arguments-multiple-input-paths index 724b074..1725633 100644 --- a/tests/snapshots/success-no-arguments-multiple-input-paths +++ b/tests/snapshots/success-no-arguments-multiple-input-paths @@ -1,6 +1,6 @@ -1.26 MB . -1.26 MB . -1.26 MB dir -1.26 MB ./dir/ -256.00 KB ./dir/sub -5.29 MB total
\ No newline at end of file + 1.26 MB . + 1.26 MB . + 1.26 MB dir + 1.26 MB ./dir/ + 256.00 KB ./dir/sub + 5.29 MB total
\ No newline at end of file diff --git a/tests/snapshots/success-no-arguments-multiple-input-paths-no-total b/tests/snapshots/success-no-arguments-multiple-input-paths-no-total index 6ca39e6..2c1725a 100644 --- a/tests/snapshots/success-no-arguments-multiple-input-paths-no-total +++ b/tests/snapshots/success-no-arguments-multiple-input-paths-no-total @@ -1,5 +1,5 @@ -1.26 MB . -1.26 MB . -1.26 MB dir -1.26 MB ./dir/ -256.00 KB ./dir/sub
\ No newline at end of file + 1.26 MB . + 1.26 MB . + 1.26 MB dir + 1.26 MB ./dir/ + 256.00 KB ./dir/sub
\ No newline at end of file |