2014-05-04 20:33:14 +00:00
|
|
|
pub enum Column {
|
|
|
|
Permissions,
|
|
|
|
FileName,
|
|
|
|
FileSize(bool),
|
2014-06-22 07:09:16 +00:00
|
|
|
Blocks,
|
2014-06-26 22:26:27 +00:00
|
|
|
User,
|
2014-05-05 10:29:50 +00:00
|
|
|
Group,
|
2014-06-22 06:40:40 +00:00
|
|
|
HardLinks,
|
2014-06-22 06:44:00 +00:00
|
|
|
Inode,
|
2014-05-04 20:33:14 +00:00
|
|
|
}
|
2014-06-03 20:14:35 +00:00
|
|
|
|
|
|
|
// 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,
|
2014-06-22 06:40:40 +00:00
|
|
|
HardLinks => Right,
|
2014-06-22 06:44:00 +00:00
|
|
|
Inode => Right,
|
2014-06-22 07:09:16 +00:00
|
|
|
Blocks => Right,
|
2014-06-03 20:14:35 +00:00
|
|
|
_ => Left,
|
|
|
|
}
|
|
|
|
}
|
2014-06-23 17:26:35 +00:00
|
|
|
|
|
|
|
pub fn header(&self) -> &'static str {
|
|
|
|
match *self {
|
|
|
|
Permissions => "Permissions",
|
|
|
|
FileName => "Name",
|
|
|
|
FileSize(_) => "Size",
|
|
|
|
Blocks => "Blocks",
|
2014-06-26 22:26:27 +00:00
|
|
|
User => "User",
|
2014-06-23 17:26:35 +00:00
|
|
|
Group => "Group",
|
|
|
|
HardLinks => "Links",
|
|
|
|
Inode => "inode",
|
|
|
|
}
|
|
|
|
}
|
2014-06-03 20:14:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// An Alignment is used to pad a string to a certain length, letting
|
2014-06-28 14:40:12 +00:00
|
|
|
// it pick which end it puts the text on. It takes the amount of
|
|
|
|
// padding to apply, rather than the width the text should end up,
|
|
|
|
// because these strings are usually full of control characters.
|
2014-06-03 20:14:35 +00:00
|
|
|
|
|
|
|
impl Alignment {
|
2014-06-28 14:40:12 +00:00
|
|
|
pub fn pad_string(&self, string: &String, padding: uint) -> String {
|
2014-06-03 20:14:35 +00:00
|
|
|
match *self {
|
2014-06-30 08:59:54 +00:00
|
|
|
Left => string.clone().append(" ".to_string().repeat(padding).as_slice()),
|
|
|
|
Right => " ".to_string().repeat(padding).append(string.as_slice()),
|
2014-06-03 20:14:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|