mirror of
https://github.com/Llewellynvdm/exa.git
synced 2024-06-26 02:32:35 +00:00
76 lines
1.9 KiB
Rust
76 lines
1.9 KiB
Rust
use std::iter::repeat;
|
|
|
|
pub enum Column {
|
|
Permissions,
|
|
FileName,
|
|
FileSize(SizeFormat),
|
|
Blocks,
|
|
User,
|
|
Group,
|
|
HardLinks,
|
|
Inode,
|
|
}
|
|
|
|
impl Copy for Column { }
|
|
|
|
pub enum SizeFormat {
|
|
DecimalBytes,
|
|
BinaryBytes,
|
|
JustBytes,
|
|
}
|
|
|
|
impl Copy for SizeFormat { }
|
|
|
|
// Each column can pick its own alignment. Usually, numbers are
|
|
// right-aligned, and text is left-aligned.
|
|
|
|
pub enum Alignment {
|
|
Left, Right,
|
|
}
|
|
|
|
impl Copy for Alignment { }
|
|
|
|
impl Column {
|
|
pub fn alignment(&self) -> Alignment {
|
|
match *self {
|
|
Column::FileSize(_) => Alignment::Right,
|
|
Column::HardLinks => Alignment::Right,
|
|
Column::Inode => Alignment::Right,
|
|
Column::Blocks => Alignment::Right,
|
|
_ => Alignment::Left,
|
|
}
|
|
}
|
|
|
|
pub fn header(&self) -> &'static str {
|
|
match *self {
|
|
Column::Permissions => "Permissions",
|
|
Column::FileName => "Name",
|
|
Column::FileSize(_) => "Size",
|
|
Column::Blocks => "Blocks",
|
|
Column::User => "User",
|
|
Column::Group => "Group",
|
|
Column::HardLinks => "Links",
|
|
Column::Inode => "inode",
|
|
}
|
|
}
|
|
}
|
|
|
|
fn spaces(length: uint) -> String {
|
|
repeat(" ").take(length).collect()
|
|
}
|
|
|
|
// An Alignment is used to pad a string to a certain length, letting
|
|
// 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 {
|
|
pub fn pad_string(&self, string: &String, padding: uint) -> String {
|
|
match *self {
|
|
Alignment::Left => format!("{}{}", string, spaces(padding).as_slice()),
|
|
Alignment::Right => format!("{}{}", spaces(padding), string.as_slice()),
|
|
}
|
|
}
|
|
}
|
|
|