diff options
Diffstat (limited to 'src/common.rs')
-rw-r--r-- | src/common.rs | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/src/common.rs b/src/common.rs index 1440cc4..a9eabff 100644 --- a/src/common.rs +++ b/src/common.rs @@ -60,6 +60,18 @@ impl ByteFormat { _ => 10, } } + pub fn total_width(&self) -> usize { + use ByteFormat::*; + const THE_SPACE_BETWEEN_UNIT_AND_NUMBER: usize = 1; + + self.width() + + match self { + Binary | MiB | GiB => 3, + Metric | MB | GB => 2, + Bytes => 1, + } + + THE_SPACE_BETWEEN_UNIT_AND_NUMBER + } pub fn display(self, bytes: u64) -> ByteFormatDisplay { ByteFormatDisplay { format: self, |