exa/src/column.rs

58 lines
1.6 KiB
Rust
Raw Normal View History

pub enum Column {
Permissions,
FileName,
FileSize(bool),
2014-06-22 07:09:16 +00:00
Blocks,
User,
Group,
HardLinks,
2014-06-22 06:44:00 +00:00
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 {
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-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
}
}
}
// 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.
impl Alignment {
2014-06-28 14:40:12 +00:00
pub fn pad_string(&self, string: &String, padding: uint) -> String {
match *self {
Alignment::Left => format!("{}{}", string, " ".repeat(padding).as_slice()),
Alignment::Right => format!("{}{}", " ".repeat(padding), string.as_slice()),
}
}
}