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 {
|
2014-11-23 21:29:11 +00:00
|
|
|
Column::FileSize(_) => Alignment::Right,
|
|
|
|
Column::HardLinks => Alignment::Right,
|
|
|
|
Column::Inode => Alignment::Right,
|
|
|
|
Column::Blocks => Alignment::Right,
|
|
|
|
_ => Alignment::Left,
|
2014-06-03 20:14:35 +00:00
|
|
|
}
|
|
|
|
}
|
2014-06-23 17:26:35 +00:00
|
|
|
|
|
|
|
pub fn header(&self) -> &'static str {
|
|
|
|
match *self {
|
2014-11-23 21:29:11 +00:00
|
|
|
Column::Permissions => "Permissions",
|
2014-11-24 02:12:52 +00:00
|
|
|
Column::FileName => "Name",
|
2014-11-23 21:29:11 +00:00
|
|
|
Column::FileSize(_) => "Size",
|
2014-11-24 02:12:52 +00:00
|
|
|
Column::Blocks => "Blocks",
|
|
|
|
Column::User => "User",
|
|
|
|
Column::Group => "Group",
|
|
|
|
Column::HardLinks => "Links",
|
|
|
|
Column::Inode => "inode",
|
2014-06-23 17:26:35 +00:00
|
|
|
}
|
|
|
|
}
|
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-12-12 14:06:48 +00:00
|
|
|
Alignment::Left => format!("{}{}", string, " ".repeat(padding).as_slice()),
|
|
|
|
Alignment::Right => format!("{}{}", " ".repeat(padding), string.as_slice()),
|
2014-06-03 20:14:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|