From d4d04b7e929a99bba22aa297c84f5a636aff27df Mon Sep 17 00:00:00 2001 From: Ben S Date: Tue, 3 Feb 2015 17:03:58 +0000 Subject: [PATCH] Turn the file filter options into their own struct --- src/main.rs | 3 +-- src/options.rs | 27 ++++++++++++++++++++------- 2 files changed, 21 insertions(+), 9 deletions(-) diff --git a/src/main.rs b/src/main.rs index facf3c1..e57fa47 100644 --- a/src/main.rs +++ b/src/main.rs @@ -80,8 +80,7 @@ fn exa(options: &Options) { match Dir::readdir(&dir_path) { Ok(ref dir) => { - let unsorted_files = dir.files(false); - let files: Vec = options.transform_files(unsorted_files); + let files = options.transform_files(dir.files(false)); // When recursing, add any directories to the dirs stack // backwards: the *last* element of the stack is used each diff --git a/src/options.rs b/src/options.rs index f18083b..5a569e5 100644 --- a/src/options.rs +++ b/src/options.rs @@ -20,10 +20,15 @@ use self::Misfire::*; pub struct Options { pub dir_action: DirAction, pub path_strs: Vec, + pub filter: FileFilter, + view: View, +} + +#[derive(PartialEq, Debug, Copy)] +pub struct FileFilter { reverse: bool, show_invisibles: bool, sort_field: SortField, - view: View, } impl Options { @@ -65,20 +70,28 @@ impl Options { }; Ok(Options { - dir_action: try!(dir_action(&matches)), - path_strs: if matches.free.is_empty() { vec![ ".".to_string() ] } else { matches.free.clone() }, - reverse: matches.opt_present("reverse"), - show_invisibles: matches.opt_present("all"), - sort_field: sort_field, - view: try!(view(&matches)), + dir_action: try!(dir_action(&matches)), + path_strs: if matches.free.is_empty() { vec![ ".".to_string() ] } else { matches.free.clone() }, + view: try!(view(&matches)), + filter: FileFilter { + reverse: matches.opt_present("reverse"), + show_invisibles: matches.opt_present("all"), + sort_field: sort_field, + }, }) } + pub fn transform_files<'a>(&self, files: Vec>) -> Vec> { + self.filter.transform_files(files) + } + /// Display the files using this Option's View. pub fn view(&self, dir: Option<&Dir>, files: &[File]) { self.view.view(dir, files) } +} +impl FileFilter { /// Transform the files (sorting, reversing, filtering) before listing them. pub fn transform_files<'a>(&self, mut files: Vec>) -> Vec> { -- GitLab