mirror of
https://github.com/Llewellynvdm/exa.git
synced 2025-01-23 13:58:23 +00:00
Move filtering to options object, too
I'd like to have as few public methods on it as possible.
This commit is contained in:
parent
1dbe20c8c5
commit
573765b62b
4
exa.rs
4
exa.rs
@ -43,11 +43,11 @@ fn exa(options: &Options, path: Path) {
|
||||
Err(e) => fail!("readdir: {}", e),
|
||||
};
|
||||
|
||||
let files: Vec<File> = options.transform_files(paths.iter().map(|path| File::from_path(path)).collect());
|
||||
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()
|
||||
.filter(|&f| options.show(f))
|
||||
.map(|f| columns.iter().map(|c| f.display(c)).collect())
|
||||
.collect();
|
||||
|
||||
|
@ -45,7 +45,7 @@ impl Options {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn show(&self, f: &File) -> bool {
|
||||
fn show(&self, f: &File) -> bool {
|
||||
if self.showInvisibles {
|
||||
true
|
||||
} else {
|
||||
@ -53,8 +53,10 @@ impl Options {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn transform_files<'a>(&self, unordered_files: Vec<File<'a>>) -> Vec<File<'a>> {
|
||||
let mut files = unordered_files.clone();
|
||||
pub fn transform_files<'a>(&self, unordered_files: &'a Vec<File<'a>>) -> Vec<&'a File<'a>> {
|
||||
let mut files: Vec<&'a File<'a>> = unordered_files.iter()
|
||||
.filter(|&f| self.show(f))
|
||||
.collect();
|
||||
|
||||
match self.sortField {
|
||||
Name => files.sort_by(|a, b| a.name.cmp(&b.name)),
|
||||
|
Loading…
x
Reference in New Issue
Block a user