Remove filter and dir_action from Details

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.
This commit is contained in:
Benjamin Sago 2017-06-26 08:28:32 +01:00
parent 14144e2ad3
commit 65d94636d7
4 changed files with 17 additions and 25 deletions

View File

@ -173,7 +173,7 @@ impl<'w, W: Write + 'w> Exa<'w, W> {
match *mode { match *mode {
Mode::Lines => lines::Render { files, colours, classify }.render(self.writer), Mode::Lines => lines::Render { files, colours, classify }.render(self.writer),
Mode::Grid(ref opts) => grid::Render { files, colours, classify, opts }.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), Mode::GridDetails(ref grid, ref details) => grid_details::Render { dir, files, colours, classify, grid, details }.render(self.writer),
} }
} }

View File

@ -135,7 +135,7 @@ impl Options {
fn deduce(matches: &getopts::Matches) -> Result<Options, Misfire> { fn deduce(matches: &getopts::Matches) -> Result<Options, Misfire> {
let dir_action = DirAction::deduce(matches)?; let dir_action = DirAction::deduce(matches)?;
let filter = FileFilter::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 }) Ok(Options { dir_action, view, filter })
} }

View File

@ -6,7 +6,7 @@ use output::Colours;
use output::{grid, details}; use output::{grid, details};
use output::column::{Columns, TimeTypes, SizeFormat}; use output::column::{Columns, TimeTypes, SizeFormat};
use output::file_name::Classify; use output::file_name::Classify;
use options::{FileFilter, DirAction, Misfire}; use options::Misfire;
use fs::feature::xattr; use fs::feature::xattr;
@ -21,8 +21,8 @@ pub struct View {
impl View { impl View {
/// Determine which view to use and all of that views arguments. /// Determine which view to use and all of that views arguments.
pub fn deduce(matches: &getopts::Matches, filter: FileFilter, dir_action: DirAction) -> Result<View, Misfire> { pub fn deduce(matches: &getopts::Matches) -> Result<View, Misfire> {
let mode = Mode::deduce(matches, filter, dir_action)?; let mode = Mode::deduce(matches)?;
let colours = Colours::deduce(matches)?; let colours = Colours::deduce(matches)?;
let classify = Classify::deduce(matches); let classify = Classify::deduce(matches);
Ok(View { mode, colours, classify }) Ok(View { mode, colours, classify })
@ -42,7 +42,7 @@ pub enum Mode {
impl Mode { impl Mode {
/// Determine the mode from the command-line arguments. /// Determine the mode from the command-line arguments.
pub fn deduce(matches: &getopts::Matches, filter: FileFilter, dir_action: DirAction) -> Result<Mode, Misfire> { pub fn deduce(matches: &getopts::Matches) -> Result<Mode, Misfire> {
use options::misfire::Misfire::*; use options::misfire::Misfire::*;
let long = || { let long = || {
@ -56,8 +56,6 @@ impl Mode {
let details = details::Options { let details = details::Options {
columns: Some(Columns::deduce(matches)?), columns: Some(Columns::deduce(matches)?),
header: matches.opt_present("header"), header: matches.opt_present("header"),
recurse: dir_action.recurse_options(),
filter: filter.clone(),
xattr: xattr::ENABLED && matches.opt_present("extended"), xattr: xattr::ENABLED && matches.opt_present("extended"),
}; };
@ -100,8 +98,6 @@ impl Mode {
let details = details::Options { let details = details::Options {
columns: None, columns: None,
header: false, header: false,
recurse: dir_action.recurse_options(),
filter: filter.clone(), // TODO: clone
xattr: false, xattr: false,
}; };
@ -125,8 +121,6 @@ impl Mode {
let details = details::Options { let details = details::Options {
columns: None, columns: None,
header: false, header: false,
recurse: dir_action.recurse_options(),
filter: filter.clone(),
xattr: false, xattr: false,
}; };

View File

@ -120,14 +120,6 @@ pub struct Options {
/// columns are *added* to this list, such as the Git column. /// columns are *added* to this list, such as the Git column.
pub columns: Option<Columns>, pub columns: Option<Columns>,
/// 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<RecurseOptions>,
/// How to sort and filter the files after getting their details.
pub filter: FileFilter,
/// Whether to show a header line or not. /// Whether to show a header line or not.
pub header: bool, pub header: bool,
@ -224,6 +216,14 @@ pub struct Render<'a> {
pub colours: &'a Colours, pub colours: &'a Colours,
pub classify: Classify, pub classify: Classify,
pub opts: &'a Options, 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<RecurseOptions>,
/// How to sort and filter the files after getting their details.
pub filter: &'a FileFilter,
} }
impl<'a> Render<'a> { impl<'a> Render<'a> {
@ -294,8 +294,6 @@ impl<'a> Render<'a> {
let file_eggs = file_eggs.clone(); let file_eggs = file_eggs.clone();
let table = table.clone(); let table = table.clone();
let recurse = self.opts.recurse;
scoped.execute(move || { scoped.execute(move || {
let mut errors = Vec::new(); let mut errors = Vec::new();
let mut xattrs = Vec::new(); let mut xattrs = Vec::new();
@ -315,7 +313,7 @@ impl<'a> Render<'a> {
let mut dir = None; 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 file.is_directory() && r.tree && !r.is_too_deep(depth) {
if let Ok(d) = file.to_dir(false) { if let Ok(d) = file.to_dir(false) {
dir = Some(d); 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(); let num_eggs = file_eggs.len();
for (index, egg) in file_eggs.into_iter().enumerate() { 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() { if !files.is_empty() {
for xattr in egg.xattrs { for xattr in egg.xattrs {