Darken file size suffixes

I think this is necessary because 'bytes' currently has no 'B' suffix, and it's
kind of hard to distinguish a long number from a suffix.
This commit is contained in:
Ben S 2014-06-03 21:20:17 +01:00
parent e5e426fc60
commit bc4df2cf3c
2 changed files with 6 additions and 6 deletions

View File

@ -89,13 +89,13 @@ impl<'a> File<'a> {
if self.stat.kind == io::TypeDirectory {
Black.bold().paint("-")
} else {
let size_str = if use_iec_prefixes {
let (size, suffix) = if use_iec_prefixes {
format_IEC_bytes(self.stat.size)
} else {
format_metric_bytes(self.stat.size)
};
return Green.bold().paint(size_str.as_slice());
return format!("{}{}", Green.bold().paint(size.as_slice()), Green.paint(suffix.as_slice()));
}
}

View File

@ -6,19 +6,19 @@ static IEC_PREFIXES: &'static [&'static str] = &[
"", "Ki", "Mi", "Gi", "Ti", "Pi", "Ei", "Zi", "Yi"
];
fn format_bytes(mut amount: u64, kilo: u64, prefixes: &[&str]) -> String {
fn format_bytes(mut amount: u64, kilo: u64, prefixes: &[&str]) -> (String, String) {
let mut prefix = 0;
while amount > kilo {
amount /= kilo;
prefix += 1;
}
format!("{}{}", amount, prefixes[prefix])
return (format!("{}", amount), prefixes[prefix].to_string());
}
pub fn format_IEC_bytes(amount: u64) -> String {
pub fn format_IEC_bytes(amount: u64) -> (String, String) {
format_bytes(amount, 1024, IEC_PREFIXES)
}
pub fn format_metric_bytes(amount: u64) -> String {
pub fn format_metric_bytes(amount: u64) -> (String, String) {
format_bytes(amount, 1000, METRIC_PREFIXES)
}