提交 0dd74a02 编写于 作者: B Ben S

Add --binary flag

This finally means that the list of columns is no longer fixed, which means it has to be generated somewhere. And guess where it got moved to? That's right, the options object! (see previous commits)
上级 573765b6
......@@ -45,17 +45,16 @@ fn exa(options: &Options, path: Path) {
let unordered_files: Vec<File> = paths.iter().map(|path| File::from_path(path)).collect();
let files: Vec<&File> = options.transform_files(&unordered_files);
let columns = options.columns();
let table: Vec<Vec<String>> = files.iter()
.map(|f| columns.iter().map(|c| f.display(c)).collect())
.map(|f| options.columns.iter().map(|c| f.display(c)).collect())
.collect();
let lengths: Vec<Vec<uint>> = table.iter()
.map(|row| row.iter().map(|col| colours::strip_formatting(col).len()).collect())
.collect();
let maxes: Vec<uint> = range(0, columns.len())
let maxes: Vec<uint> = range(0, options.columns.len())
.map(|n| lengths.iter().map(|row| *row.get(n)).max().unwrap())
.collect();
......
......@@ -13,6 +13,7 @@ pub struct Options {
pub sortField: SortField,
pub reverse: bool,
pub dirs: Vec<String>,
pub columns: ~[Column],
}
impl SortField {
......@@ -30,6 +31,7 @@ impl Options {
pub fn getopts(args: Vec<String>) -> Result<Options, getopts::Fail_> {
let opts = ~[
getopts::optflag("a", "all", "show dot-files"),
getopts::optflag("b", "binary", "use binary prefixes in file sizes"),
getopts::optflag("r", "reverse", "reverse order of files"),
getopts::optopt("s", "sort", "field to sort by", "WORD"),
];
......@@ -40,11 +42,22 @@ impl Options {
showInvisibles: matches.opt_present("all"),
reverse: matches.opt_present("reverse"),
sortField: matches.opt_str("sort").map(|word| SortField::from_word(word)).unwrap_or(Name),
dirs: matches.free,
dirs: matches.free.clone(),
columns: Options::columns(matches),
})
}
}
fn columns(matches: getopts::Matches) -> ~[Column] {
return ~[
Permissions,
FileSize(matches.opt_present("binary")),
User,
Group,
FileName,
];
}
fn show(&self, f: &File) -> bool {
if self.showInvisibles {
true
......@@ -74,15 +87,4 @@ impl Options {
return files;
}
pub fn columns(&self) -> ~[Column] {
return ~[
Permissions,
FileSize(false),
User,
Group,
FileName,
];
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册