From 65d94636d731818c9bb9883537f9c7e689b6ab07 Mon Sep 17 00:00:00 2001 From: Benjamin Sago Date: Mon, 26 Jun 2017 08:28:32 +0100 Subject: [PATCH] Remove filter and dir_action from Details MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit These two fields were originally needed to determine how to recurse when using tree view. However, as there was no distinction between the “options parsed from the command-line” Details and the “values needed to render a table” Details, these had to be threaded through the options parser as a special-case to end up in the right struct. No more! Because there are separate structs for options and rendering, we can just add them in later. --- src/exa.rs | 2 +- src/options/mod.rs | 2 +- src/options/view.rs | 14 ++++---------- src/output/details.rs | 24 +++++++++++------------- 4 files changed, 17 insertions(+), 25 deletions(-) diff --git a/src/exa.rs b/src/exa.rs index fbc0aea..c1ebe8c 100644 --- a/src/exa.rs +++ b/src/exa.rs @@ -173,7 +173,7 @@ impl<'w, W: Write + 'w> Exa<'w, W> { match *mode { Mode::Lines => lines::Render { files, colours, classify }.render(self.writer), Mode::Grid(ref opts) => grid::Render { files, colours, classify, opts }.render(self.writer), - Mode::Details(ref opts) => details::Render { dir, files, colours, classify, opts }.render(self.writer), + Mode::Details(ref opts) => details::Render { dir, files, colours, classify, opts, filter: &self.options.filter, recurse: self.options.dir_action.recurse_options() }.render(self.writer), Mode::GridDetails(ref grid, ref details) => grid_details::Render { dir, files, colours, classify, grid, details }.render(self.writer), } } diff --git a/src/options/mod.rs b/src/options/mod.rs index a368f8a..c37ff42 100644 --- a/src/options/mod.rs +++ b/src/options/mod.rs @@ -135,7 +135,7 @@ impl Options { fn deduce(matches: &getopts::Matches) -> Result { let dir_action = DirAction::deduce(matches)?; let filter = FileFilter::deduce(matches)?; - let view = View::deduce(matches, filter.clone(), dir_action)?; + let view = View::deduce(matches)?; Ok(Options { dir_action, view, filter }) } diff --git a/src/options/view.rs b/src/options/view.rs index 1633887..7bc9298 100644 --- a/src/options/view.rs +++ b/src/options/view.rs @@ -6,7 +6,7 @@ use output::Colours; use output::{grid, details}; use output::column::{Columns, TimeTypes, SizeFormat}; use output::file_name::Classify; -use options::{FileFilter, DirAction, Misfire}; +use options::Misfire; use fs::feature::xattr; @@ -21,8 +21,8 @@ pub struct View { impl View { /// Determine which view to use and all of that view’s arguments. - pub fn deduce(matches: &getopts::Matches, filter: FileFilter, dir_action: DirAction) -> Result { - let mode = Mode::deduce(matches, filter, dir_action)?; + pub fn deduce(matches: &getopts::Matches) -> Result { + let mode = Mode::deduce(matches)?; let colours = Colours::deduce(matches)?; let classify = Classify::deduce(matches); Ok(View { mode, colours, classify }) @@ -42,7 +42,7 @@ pub enum Mode { impl Mode { /// Determine the mode from the command-line arguments. - pub fn deduce(matches: &getopts::Matches, filter: FileFilter, dir_action: DirAction) -> Result { + pub fn deduce(matches: &getopts::Matches) -> Result { use options::misfire::Misfire::*; let long = || { @@ -56,8 +56,6 @@ impl Mode { let details = details::Options { columns: Some(Columns::deduce(matches)?), header: matches.opt_present("header"), - recurse: dir_action.recurse_options(), - filter: filter.clone(), xattr: xattr::ENABLED && matches.opt_present("extended"), }; @@ -100,8 +98,6 @@ impl Mode { let details = details::Options { columns: None, header: false, - recurse: dir_action.recurse_options(), - filter: filter.clone(), // TODO: clone xattr: false, }; @@ -125,8 +121,6 @@ impl Mode { let details = details::Options { columns: None, header: false, - recurse: dir_action.recurse_options(), - filter: filter.clone(), xattr: false, }; diff --git a/src/output/details.rs b/src/output/details.rs index 405fec9..899bc89 100644 --- a/src/output/details.rs +++ b/src/output/details.rs @@ -120,14 +120,6 @@ pub struct Options { /// columns are *added* to this list, such as the Git column. pub columns: Option, - /// Whether to recurse through directories with a tree view, and if so, - /// which options to use. This field is only relevant here if the `tree` - /// field of the RecurseOptions is `true`. - pub recurse: Option, - - /// How to sort and filter the files after getting their details. - pub filter: FileFilter, - /// Whether to show a header line or not. pub header: bool, @@ -224,6 +216,14 @@ pub struct Render<'a> { pub colours: &'a Colours, pub classify: Classify, pub opts: &'a Options, + + /// Whether to recurse through directories with a tree view, and if so, + /// which options to use. This field is only relevant here if the `tree` + /// field of the RecurseOptions is `true`. + pub recurse: Option, + + /// How to sort and filter the files after getting their details. + pub filter: &'a FileFilter, } impl<'a> Render<'a> { @@ -294,8 +294,6 @@ impl<'a> Render<'a> { let file_eggs = file_eggs.clone(); let table = table.clone(); - let recurse = self.opts.recurse; - scoped.execute(move || { let mut errors = Vec::new(); let mut xattrs = Vec::new(); @@ -315,7 +313,7 @@ impl<'a> Render<'a> { let mut dir = None; - if let Some(r) = recurse { + if let Some(r) = self.recurse { if file.is_directory() && r.tree && !r.is_too_deep(depth) { if let Ok(d) = file.to_dir(false) { dir = Some(d); @@ -329,7 +327,7 @@ impl<'a> Render<'a> { } }); - self.opts.filter.sort_files(&mut file_eggs); + self.filter.sort_files(&mut file_eggs); let num_eggs = file_eggs.len(); for (index, egg) in file_eggs.into_iter().enumerate() { @@ -353,7 +351,7 @@ impl<'a> Render<'a> { } } - self.opts.filter.filter_child_files(&mut files); + self.filter.filter_child_files(&mut files); if !files.is_empty() { for xattr in egg.xattrs {