mirror of
https://github.com/Llewellynvdm/exa.git
synced 2024-12-24 17:40:25 +00:00
Add header row with -h option
This commit is contained in:
parent
48284e0aef
commit
038143682c
13
column.rs
13
column.rs
@ -26,6 +26,19 @@ impl Column {
|
||||
_ => 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
|
||||
|
7
exa.rs
7
exa.rs
@ -8,6 +8,7 @@ use file::File;
|
||||
use dir::Dir;
|
||||
use options::Options;
|
||||
use unix::Unix;
|
||||
use colours::Plain;
|
||||
|
||||
pub mod colours;
|
||||
pub mod column;
|
||||
@ -72,10 +73,14 @@ fn exa(options: &Options, print_header: bool, string: String) {
|
||||
|
||||
let mut cache = Unix::empty_cache();
|
||||
|
||||
let table: Vec<Vec<String>> = files.iter()
|
||||
let mut table: Vec<Vec<String>> = files.iter()
|
||||
.map(|f| options.columns.iter().map(|c| f.display(c, &mut cache)).collect())
|
||||
.collect();
|
||||
|
||||
if options.header {
|
||||
table.unshift(options.columns.iter().map(|c| Plain.underline().paint(c.header())).collect());
|
||||
}
|
||||
|
||||
// Each column needs to have its invisible colour-formatting
|
||||
// characters stripped before it has its width calculated, or the
|
||||
// width will be incorrect and the columns won't line up properly.
|
||||
|
@ -16,6 +16,7 @@ pub struct Options {
|
||||
pub reverse: bool,
|
||||
pub dirs: Vec<String>,
|
||||
pub columns: Vec<Column>,
|
||||
pub header: bool,
|
||||
}
|
||||
|
||||
impl SortField {
|
||||
@ -35,6 +36,7 @@ impl Options {
|
||||
getopts::optflag("a", "all", "show dot-files"),
|
||||
getopts::optflag("b", "binary", "use binary prefixes in file sizes"),
|
||||
getopts::optflag("g", "group", "show group as well as user"),
|
||||
getopts::optflag("h", "header", "show a header row at the top"),
|
||||
getopts::optflag("i", "inode", "show each file's inode number"),
|
||||
getopts::optflag("l", "links", "show number of hard links"),
|
||||
getopts::optflag("r", "reverse", "reverse order of files"),
|
||||
@ -47,6 +49,7 @@ impl Options {
|
||||
Ok(matches) => Ok(Options {
|
||||
showInvisibles: matches.opt_present("all"),
|
||||
reverse: matches.opt_present("reverse"),
|
||||
header: matches.opt_present("header"),
|
||||
sortField: matches.opt_str("sort").map(|word| SortField::from_word(word)).unwrap_or(Name),
|
||||
dirs: matches.free.clone(),
|
||||
columns: Options::columns(matches),
|
||||
|
Loading…
Reference in New Issue
Block a user