From da00e2fda2ec131232bc747f1b7d6da5d25d8a41 Mon Sep 17 00:00:00 2001 From: Benjamin Sago Date: Sat, 12 Aug 2017 22:49:16 +0100 Subject: [PATCH] Thread the row threshold through grid_details MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit No new features here, just some restructuring. Mode::GridDetails was nice and elegant with those two fields, but now there’s a grid-details-only option the elegance has gone out the window. --- src/exa.rs | 16 ++++++++++++---- src/options/mod.rs | 5 ++--- src/options/view.rs | 8 ++++---- src/output/grid_details.rs | 8 ++++++++ src/output/mod.rs | 2 +- 5 files changed, 27 insertions(+), 12 deletions(-) diff --git a/src/exa.rs b/src/exa.rs index 45106e5..0641006 100644 --- a/src/exa.rs +++ b/src/exa.rs @@ -181,10 +181,18 @@ impl<'args, 'w, W: Write + 'w> Exa<'args, 'w, W> { let View { ref mode, ref colours, ref style } = self.options.view; match *mode { - Mode::Lines => lines::Render { files, colours, style }.render(self.writer), - Mode::Grid(ref opts) => grid::Render { files, colours, style, opts }.render(self.writer), - Mode::Details(ref opts) => details::Render { dir, files, colours, style, 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, style, grid, details, filter: &self.options.filter, row_threshold: Some(10) }.render(self.writer), + Mode::Lines => { + lines::Render { files, colours, style }.render(self.writer) + } + Mode::Grid(ref opts) => { + grid::Render { files, colours, style, opts }.render(self.writer) + } + Mode::Details(ref opts) => { + details::Render { dir, files, colours, style, opts, filter: &self.options.filter, recurse: self.options.dir_action.recurse_options() }.render(self.writer) + } + Mode::GridDetails(ref opts) => { + grid_details::Render { dir, files, colours, style, grid: &opts.grid, details: &opts.details, filter: &self.options.filter, row_threshold: opts.row_threshold }.render(self.writer) + } } } else { diff --git a/src/options/mod.rs b/src/options/mod.rs index 40469ab..1360a63 100644 --- a/src/options/mod.rs +++ b/src/options/mod.rs @@ -73,8 +73,7 @@ use std::ffi::{OsStr, OsString}; use fs::dir_action::DirAction; use fs::filter::FileFilter; -use output::{View, Mode}; -use output::details; +use output::{View, Mode, details, grid_details}; mod dir_action; mod filter; @@ -145,7 +144,7 @@ impl Options { pub fn should_scan_for_git(&self) -> bool { match self.view.mode { Mode::Details(details::Options { table: Some(ref table), .. }) | - Mode::GridDetails(_, details::Options { table: Some(ref table), .. }) => table.extra_columns.should_scan_for_git(), + Mode::GridDetails(grid_details::Options { details: details::Options { table: Some(ref table), .. }, .. }) => table.extra_columns.should_scan_for_git(), _ => false, } } diff --git a/src/options/view.rs b/src/options/view.rs index 6bceb65..33ded47 100644 --- a/src/options/view.rs +++ b/src/options/view.rs @@ -1,5 +1,5 @@ use output::Colours; -use output::{View, Mode, grid, details}; +use output::{View, Mode, grid, details, grid_details}; use output::table::{TimeTypes, Environment, SizeFormat, Columns, Options as TableOptions}; use output::file_name::{Classify, FileStyle}; use output::time::TimeFormat; @@ -96,7 +96,7 @@ impl Mode { let details = long()?; if matches.has(&flags::GRID)? { match other_options_scan()? { - Mode::Grid(grid) => return Ok(Mode::GridDetails(grid, details)), + Mode::Grid(grid) => return Ok(Mode::GridDetails(grid_details::Options { grid, details, row_threshold: Some(5) })), others => return Ok(others), }; } @@ -643,8 +643,8 @@ mod test { test!(ell: Mode <- ["-l"], None; Both => like Ok(Mode::Details(_))); // Grid-details views - test!(lid: Mode <- ["--long", "--grid"], None; Both => like Ok(Mode::GridDetails(_, _))); - test!(leg: Mode <- ["-lG"], None; Both => like Ok(Mode::GridDetails(_, _))); + test!(lid: Mode <- ["--long", "--grid"], None; Both => like Ok(Mode::GridDetails(_))); + test!(leg: Mode <- ["-lG"], None; Both => like Ok(Mode::GridDetails(_))); // Options that do nothing without --long diff --git a/src/output/grid_details.rs b/src/output/grid_details.rs index 9814264..59d0d7a 100644 --- a/src/output/grid_details.rs +++ b/src/output/grid_details.rs @@ -18,6 +18,14 @@ use output::table::{Table, Row as TableRow, Options as TableOptions}; use output::tree::{TreeParams, TreeDepth}; +#[derive(Debug)] +pub struct Options { + pub grid: GridOptions, + pub details: DetailsOptions, + pub row_threshold: Option, +} + + pub struct Render<'a> { /// The directory that’s being rendered here. diff --git a/src/output/mod.rs b/src/output/mod.rs index 672cb4f..e5e42b1 100644 --- a/src/output/mod.rs +++ b/src/output/mod.rs @@ -33,6 +33,6 @@ pub struct View { pub enum Mode { Grid(grid::Options), Details(details::Options), - GridDetails(grid::Options, details::Options), + GridDetails(grid_details::Options), Lines, }