mirror of
https://github.com/Llewellynvdm/exa.git
synced 2024-12-24 17:40:25 +00:00
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:
parent
e5e426fc60
commit
bc4df2cf3c
4
file.rs
4
file.rs
@ -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()));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user