summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSebastian Thiel <sthiel@thoughtworks.com>2019-06-04 13:31:07 +0530
committerSebastian Thiel <sthiel@thoughtworks.com>2019-06-04 13:31:07 +0530
commita5c8e37b970169913ab72ea691b89aeeeffad403 (patch)
tree8f72853e8cbd6d3e3e01bef5e05969c364deb5e5
parent7d451f968908549babd06e7858d7a5263b1737a3 (diff)
Properly fix byte column width handling
-rw-r--r--src/aggregate.rs5
-rw-r--r--src/common.rs11
-rw-r--r--src/interactive/widgets/entries.rs5
-rw-r--r--src/interactive/widgets/footer.rs2
-rw-r--r--tests/snapshots/failure-no-arguments-multiple-input-paths-some-not-existing12
-rw-r--r--tests/snapshots/success-bytes-binary14
-rw-r--r--tests/snapshots/success-bytes-only14
-rw-r--r--tests/snapshots/success-no-arguments14
-rw-r--r--tests/snapshots/success-no-arguments-multiple-input-paths12
-rw-r--r--tests/snapshots/success-no-arguments-multiple-input-paths-no-sort12
-rw-r--r--tests/snapshots/success-no-arguments-multiple-input-paths-no-total10
-rw-r--r--tests/snapshots/success-no-arguments-multiple-input-paths-statistics12
-rw-r--r--tests/snapshots/success-no-arguments-no-sort14
13 files changed, 73 insertions, 64 deletions
diff --git a/src/aggregate.rs b/src/aggregate.rs
index 6b616e8..6ca9820 100644
--- a/src/aggregate.rs
+++ b/src/aggregate.rs
@@ -112,8 +112,8 @@ fn write_path<C: fmt::Display>(
) -> Result<(), io::Error> {
writeln!(
out,
- "{byte_color}{:>10}{byte_color_reset}\t{path_color}{}{path_color_reset}{}",
- options.byte_format.display(num_bytes),
+ "{byte_color}{:>byte_column_width$}{byte_color_reset} {path_color}{}{path_color_reset}{}",
+ options.byte_format.display(num_bytes).to_string(), // needed for formatting to work (unless we implement it ourselves
path.as_ref().display(),
if num_errors == 0 {
Cow::Borrowed("")
@@ -124,6 +124,7 @@ fn write_path<C: fmt::Display>(
byte_color_reset = options.color.display(color::Fg(color::Reset)),
path_color = options.color.display(path_color),
path_color_reset = options.color.display(color::Fg(color::Reset)),
+ byte_column_width = options.byte_format.width()
)
}
diff --git a/src/common.rs b/src/common.rs
index eefcceb..0d688cd 100644
--- a/src/common.rs
+++ b/src/common.rs
@@ -62,6 +62,13 @@ pub enum ByteFormat {
}
impl ByteFormat {
+ pub fn width(&self) -> usize {
+ use ByteFormat::*;
+ match self {
+ Metric | Binary => 10,
+ Bytes => 12,
+ }
+ }
pub fn display(&self, bytes: u64) -> ByteFormatDisplay {
ByteFormatDisplay {
format: *self,
@@ -81,7 +88,7 @@ impl fmt::Display for ByteFormatDisplay {
use ByteFormat::*;
let binary = match self.format {
- Bytes => return write!(f, "{:>10} b", self.bytes),
+ Bytes => return write!(f, "{} b", self.bytes),
Binary => true,
Metric => false,
};
@@ -92,7 +99,7 @@ impl fmt::Display for ByteFormatDisplay {
match (splits.next(), splits.next()) {
(Some(bytes), Some(unit)) => write!(
f,
- "{:>8} {:>unit_width$}",
+ "{} {:>unit_width$}",
bytes,
unit,
unit_width = match self.format {
diff --git a/src/interactive/widgets/entries.rs b/src/interactive/widgets/entries.rs
index 82fb5a5..aac7200 100644
--- a/src/interactive/widgets/entries.rs
+++ b/src/interactive/widgets/entries.rs
@@ -81,14 +81,15 @@ impl<'a, 'b> Widget for Entries<'a, 'b> {
Text::Styled(
fill_background_to_right(
format!(
- "{} | {:>5.02}% | {}{}",
- display.byte_format.display(w.size),
+ "{:>byte_column_width$} | {:>5.02}% | {}{}",
+ display.byte_format.display(w.size).to_string(), // we would have to impl alignment/padding ourselves otherwise...
(w.size as f64 / total as f64) * 100.0,
match path_of(*node_idx) {
ref p if p.is_dir() && !is_top(*root) => "/",
_ => " ",
},
w.name.to_string_lossy(),
+ byte_column_width = display.byte_format.width()
),
area.width,
)
diff --git a/src/interactive/widgets/footer.rs b/src/interactive/widgets/footer.rs
index c5ef4c7..1b344fd 100644
--- a/src/interactive/widgets/footer.rs
+++ b/src/interactive/widgets/footer.rs
@@ -25,7 +25,7 @@ impl Widget for Footer {
format!(
" Total disk usage: {} Entries: {} ",
match self.total_bytes {
- Some(b) => format!("{}", self.format.display(b)).trim().to_owned(),
+ Some(b) => format!("{}", self.format.display(b)).to_owned(),
None => "-".to_owned(),
},
self.entries_traversed,
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 6166323..143cdb1 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 @@
- 0.00 B foo <1 IO Error(s)>
- 0.00 B bar <1 IO Error(s)>
- 0.00 B baz <1 IO Error(s)>
- 1.26 MB .
- 1.26 MB .
- 2.52 MB total <3 IO Error(s)> \ No newline at end of file
+ 0.00 B foo <1 IO Error(s)>
+ 0.00 B bar <1 IO Error(s)>
+ 0.00 B baz <1 IO Error(s)>
+ 1.26 MB .
+ 1.26 MB .
+ 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 7a43a1a..42bcd40 100644
--- a/tests/snapshots/success-bytes-binary
+++ b/tests/snapshots/success-bytes-binary
@@ -1,7 +1,7 @@
- 0.00 B b.empty
- 123.00 B z123.b
- 256.00 B a
- 256.00 B c.lnk
- 666.00 B .hidden.666
- 1.20 MiB dir
- 1.20 MiB total \ No newline at end of file
+ 0.00 B b.empty
+123.00 B z123.b
+256.00 B a
+256.00 B c.lnk
+666.00 B .hidden.666
+ 1.20 MiB dir
+ 1.20 MiB total \ No newline at end of file
diff --git a/tests/snapshots/success-bytes-only b/tests/snapshots/success-bytes-only
index 5ad3f75..966bea6 100644
--- a/tests/snapshots/success-bytes-only
+++ b/tests/snapshots/success-bytes-only
@@ -1,7 +1,7 @@
- 0 b b.empty
- 123 b z123.b
- 256 b a
- 256 b c.lnk
- 666 b .hidden.666
- 1258024 b dir
- 1259325 b total \ No newline at end of file
+ 0 b b.empty
+ 123 b z123.b
+ 256 b a
+ 256 b c.lnk
+ 666 b .hidden.666
+ 1258024 b dir
+ 1259325 b total \ No newline at end of file
diff --git a/tests/snapshots/success-no-arguments b/tests/snapshots/success-no-arguments
index 8348016..400782c 100644
--- a/tests/snapshots/success-no-arguments
+++ b/tests/snapshots/success-no-arguments
@@ -1,7 +1,7 @@
- 0.00 B b.empty
- 123.00 B z123.b
- 256.00 B a
- 256.00 B c.lnk
- 666.00 B .hidden.666
- 1.26 MB dir
- 1.26 MB total \ No newline at end of file
+ 0.00 B b.empty
+ 123.00 B z123.b
+ 256.00 B a
+ 256.00 B c.lnk
+ 666.00 B .hidden.666
+ 1.26 MB dir
+ 1.26 MB total \ 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 f157e57..e7738a5 100644
--- a/tests/snapshots/success-no-arguments-multiple-input-paths
+++ b/tests/snapshots/success-no-arguments-multiple-input-paths
@@ -1,6 +1,6 @@
- 256.00 KB ./dir/sub
- 1.26 MB dir
- 1.26 MB ./dir/
- 1.26 MB .
- 1.26 MB .
- 5.29 MB total \ No newline at end of file
+ 256.00 KB ./dir/sub
+ 1.26 MB dir
+ 1.26 MB ./dir/
+ 1.26 MB .
+ 1.26 MB .
+ 5.29 MB total \ No newline at end of file
diff --git a/tests/snapshots/success-no-arguments-multiple-input-paths-no-sort b/tests/snapshots/success-no-arguments-multiple-input-paths-no-sort
index 1725633..421330c 100644
--- a/tests/snapshots/success-no-arguments-multiple-input-paths-no-sort
+++ b/tests/snapshots/success-no-arguments-multiple-input-paths-no-sort
@@ -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 2427939..a7569f2 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 @@
- 256.00 KB ./dir/sub
- 1.26 MB dir
- 1.26 MB ./dir/
- 1.26 MB .
- 1.26 MB . \ No newline at end of file
+ 256.00 KB ./dir/sub
+ 1.26 MB dir
+ 1.26 MB ./dir/
+ 1.26 MB .
+ 1.26 MB . \ No newline at end of file
diff --git a/tests/snapshots/success-no-arguments-multiple-input-paths-statistics b/tests/snapshots/success-no-arguments-multiple-input-paths-statistics
index 36024d6..dcc34d6 100644
--- a/tests/snapshots/success-no-arguments-multiple-input-paths-statistics
+++ b/tests/snapshots/success-no-arguments-multiple-input-paths-statistics
@@ -1,7 +1,7 @@
- 256.00 KB ./dir/sub
- 1.26 MB dir
- 1.26 MB ./dir/
- 1.26 MB .
- 1.26 MB .
- 5.29 MB total
+ 256.00 KB ./dir/sub
+ 1.26 MB dir
+ 1.26 MB ./dir/
+ 1.26 MB .
+ 1.26 MB .
+ 5.29 MB total
Statistics { entries_traversed: 46, smallest_file_in_bytes: 0, largest_file_in_bytes: 1000000 } \ No newline at end of file
diff --git a/tests/snapshots/success-no-arguments-no-sort b/tests/snapshots/success-no-arguments-no-sort
index 126d918..617e011 100644
--- a/tests/snapshots/success-no-arguments-no-sort
+++ b/tests/snapshots/success-no-arguments-no-sort
@@ -1,7 +1,7 @@
- 666.00 B .hidden.666
- 256.00 B a
- 0.00 B b.empty
- 256.00 B c.lnk
- 1.26 MB dir
- 123.00 B z123.b
- 1.26 MB total \ No newline at end of file
+ 666.00 B .hidden.666
+ 256.00 B a
+ 0.00 B b.empty
+ 256.00 B c.lnk
+ 1.26 MB dir
+ 123.00 B z123.b
+ 1.26 MB total \ No newline at end of file