diff options
author | Sebastian Thiel <sthiel@thoughtworks.com> | 2019-06-04 13:31:07 +0530 |
---|---|---|
committer | Sebastian Thiel <sthiel@thoughtworks.com> | 2019-06-04 13:31:07 +0530 |
commit | a5c8e37b970169913ab72ea691b89aeeeffad403 (patch) | |
tree | 8f72853e8cbd6d3e3e01bef5e05969c364deb5e5 /src/common.rs | |
parent | 7d451f968908549babd06e7858d7a5263b1737a3 (diff) |
Properly fix byte column width handling
Diffstat (limited to 'src/common.rs')
-rw-r--r-- | src/common.rs | 11 |
1 files changed, 9 insertions, 2 deletions
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 { |