mirror of
https://github.com/Llewellynvdm/exa.git
synced 2024-12-25 17:51:10 +00:00
Change format of file sizes to be shorter
I'm copying ls here because we don't really need the 'B' for bytes to be listed every time. I think it looks better the new way. Unlike ls, don't list directory sizes, because I've never found the pseudo-sizes they get given at all useful. Also, fix a bug where aligning columns didn't work when the number of format characters (like '\x1B' and '[') were different between each line.
This commit is contained in:
parent
d60c2ce839
commit
b116889abc
2
exa.rs
2
exa.rs
@ -82,7 +82,7 @@ fn list(options: Options, path: Path) {
|
|||||||
print!(" ");
|
print!(" ");
|
||||||
}
|
}
|
||||||
print!("{}", cell.as_slice());
|
print!("{}", cell.as_slice());
|
||||||
for _ in range(cell.len(), *length) {
|
for _ in range(colours::strip_formatting(cell).len(), *length) {
|
||||||
print!(" ");
|
print!(" ");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
12
file.rs
12
file.rs
@ -66,17 +66,19 @@ impl<'a> File<'a> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn file_size(&self, si: bool) -> StrBuf {
|
fn file_size(&self, si: bool) -> StrBuf {
|
||||||
|
// Don't report file sizes for directories. I've never looked
|
||||||
|
// at one of those numbers and gained any information from it.
|
||||||
|
if self.stat.kind == io::TypeDirectory {
|
||||||
|
Black.bold().paint("---")
|
||||||
|
} else {
|
||||||
let sizeStr = if si {
|
let sizeStr = if si {
|
||||||
formatBinaryBytes(self.stat.size)
|
formatBinaryBytes(self.stat.size)
|
||||||
} else {
|
} else {
|
||||||
formatDecimalBytes(self.stat.size)
|
formatDecimalBytes(self.stat.size)
|
||||||
};
|
};
|
||||||
|
|
||||||
return if self.stat.kind == io::TypeDirectory {
|
return Green.bold().paint(sizeStr.as_slice());
|
||||||
Green.normal()
|
}
|
||||||
} else {
|
|
||||||
Green.bold()
|
|
||||||
}.paint(sizeStr.as_slice());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn type_char(&self) -> StrBuf {
|
fn type_char(&self) -> StrBuf {
|
||||||
|
16
format.rs
16
format.rs
@ -1,16 +1,24 @@
|
|||||||
fn formatBytes(mut amount: u64, kilo: u64, prefixes: ~[&str]) -> StrBuf {
|
static METRIC_PREFIXES: &'static [&'static str] = &[
|
||||||
|
"", "K", "M", "G", "T", "P", "E", "Z", "Y"
|
||||||
|
];
|
||||||
|
|
||||||
|
static IEC_PREFIXES: &'static [&'static str] = &[
|
||||||
|
"", "Ki", "Mi", "Gi", "Ti", "Pi", "Ei", "Zi", "Yi"
|
||||||
|
];
|
||||||
|
|
||||||
|
fn formatBytes(mut amount: u64, kilo: u64, prefixes: &[&str]) -> StrBuf {
|
||||||
let mut prefix = 0;
|
let mut prefix = 0;
|
||||||
while amount > kilo {
|
while amount > kilo {
|
||||||
amount /= kilo;
|
amount /= kilo;
|
||||||
prefix += 1;
|
prefix += 1;
|
||||||
}
|
}
|
||||||
return format!("{:4}{}", amount, prefixes[prefix]);
|
format!("{}{}", amount, prefixes[prefix])
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn formatBinaryBytes(amount: u64) -> StrBuf {
|
pub fn formatBinaryBytes(amount: u64) -> StrBuf {
|
||||||
formatBytes(amount, 1024, ~[ "B ", "KiB", "MiB", "GiB", "TiB" ])
|
formatBytes(amount, 1024, IEC_PREFIXES)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn formatDecimalBytes(amount: u64) -> StrBuf {
|
pub fn formatDecimalBytes(amount: u64) -> StrBuf {
|
||||||
formatBytes(amount, 1000, ~[ "B ", "KB", "MB", "GB", "TB" ])
|
formatBytes(amount, 1000, METRIC_PREFIXES)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user