mirror of
https://github.com/Llewellynvdm/exa.git
synced 2024-11-26 05:47:32 +00:00
b337f9174d
First non-trivial change for a while... because this involves reading from the OS, we should cache as much as we can in memory. So, group membership checking is done immediately after reading a group name, as the group structure has already been populated.
71 lines
1.7 KiB
Rust
71 lines
1.7 KiB
Rust
pub enum Column {
|
|
Permissions,
|
|
FileName,
|
|
FileSize(bool),
|
|
Blocks,
|
|
User,
|
|
Group,
|
|
HardLinks,
|
|
Inode,
|
|
}
|
|
|
|
// 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,
|
|
HardLinks => Right,
|
|
Inode => Right,
|
|
Blocks => Right,
|
|
_ => Left,
|
|
}
|
|
}
|
|
|
|
pub fn header(&self) -> &'static str {
|
|
match *self {
|
|
Permissions => "Permissions",
|
|
FileName => "Name",
|
|
FileSize(_) => "Size",
|
|
Blocks => "Blocks",
|
|
User => "User",
|
|
Group => "Group",
|
|
HardLinks => "Links",
|
|
Inode => "inode",
|
|
}
|
|
}
|
|
}
|
|
|
|
// 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;
|
|
}
|
|
}
|
|
|