mirror of
https://github.com/Llewellynvdm/exa.git
synced 2024-11-25 21:37:33 +00:00
e5e426fc60
Currently there's only one numeric column, and that's the file size, so it gets special treatment. I was originally going to have a folder file size field be filled up with '-'s as far as it could go, leaving it entirely up to the column how its field gets formatted. But then I saw just one '-' working just fine, so I left it like that. In the first try, columns could do anything they want when padding a string (including changing the padding character or just changing it entirely), but now there's no point.
52 lines
1.3 KiB
Rust
52 lines
1.3 KiB
Rust
pub enum Column {
|
|
Permissions,
|
|
FileName,
|
|
FileSize(bool),
|
|
User(u64),
|
|
Group,
|
|
}
|
|
|
|
// Each column can pick its own alignment. Usually, numbers are
|
|
// right-aligned, and text is left-aligned.
|
|
|
|
pub enum Alignment {
|
|
Left, Right,
|
|
}
|
|
|
|
impl Column {
|
|
pub fn alignment(&self) -> Alignment {
|
|
match *self {
|
|
FileSize(_) => Right,
|
|
_ => Left,
|
|
}
|
|
}
|
|
}
|
|
|
|
// An Alignment is used to pad a string to a certain length, letting
|
|
// it pick which end it puts the text on. The length of the string is
|
|
// passed in specifically because it needs to be the *unformatted*
|
|
// length, rather than just the number of characters.
|
|
|
|
impl Alignment {
|
|
pub fn pad_string(&self, string: &String, string_length: uint, width: uint) -> String {
|
|
let mut str = String::new();
|
|
match *self {
|
|
Left => {
|
|
str.push_str(string.as_slice());
|
|
for _ in range(string_length, width) {
|
|
str.push_char(' ');
|
|
}
|
|
}
|
|
|
|
Right => {
|
|
for _ in range(string_length, width) {
|
|
str.push_char(' ');
|
|
}
|
|
str.push_str(string.as_slice());
|
|
},
|
|
}
|
|
return str;
|
|
}
|
|
}
|
|
|