Browse Source

By lines, I meant details

Yeah, I forgot what I was meant to be doing half-way through.

This also adds the row_threshold field, which disables the view unless there will be more than the given number of rows. Getting the row count required upgrading term_grid to a version that has that function added.
Benjamin Sago 8 years ago
parent
commit
a6ed42105d
4 changed files with 26 additions and 10 deletions
  1. 3 3
      Cargo.lock
  2. 1 1
      Cargo.toml
  3. 1 1
      src/exa.rs
  4. 21 5
      src/output/grid_details.rs

+ 3 - 3
Cargo.lock

@@ -14,7 +14,7 @@ dependencies = [
  "num_cpus 1.6.2 (registry+https://github.com/rust-lang/crates.io-index)",
  "number_prefix 0.2.7 (registry+https://github.com/rust-lang/crates.io-index)",
  "scoped_threadpool 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)",
- "term_grid 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
+ "term_grid 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)",
  "term_size 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
  "unicode-width 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)",
  "users 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -321,7 +321,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
 
 [[package]]
 name = "term_grid"
-version = "0.1.5"
+version = "0.1.6"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 dependencies = [
  "unicode-width 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -438,7 +438,7 @@ dependencies = [
 "checksum rand 0.3.16 (registry+https://github.com/rust-lang/crates.io-index)" = "eb250fd207a4729c976794d03db689c9be1d634ab5a1c9da9492a13d8fecbcdf"
 "checksum rustc-serialize 0.3.24 (registry+https://github.com/rust-lang/crates.io-index)" = "dcf128d1287d2ea9d80910b5f1120d0b8eede3fbf1abe91c40d39ea7d51e6fda"
 "checksum scoped_threadpool 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)" = "3ef399c8893e8cb7aa9696e895427fab3a6bf265977bb96e126f24ddd2cda85a"
-"checksum term_grid 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "ccc202875496cf72a683a1ecd66f0742a830e73c202bdbd21867d73dfaac8343"
+"checksum term_grid 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "b56a46b68f4aa347ba5512b1abc12dcb641ff0e9aa3cb49b007595a320e369c5"
 "checksum term_size 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e2b6b55df3198cc93372e85dd2ed817f0e38ce8cc0f22eb32391bfad9c4bf209"
 "checksum unicode-bidi 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "49f2bd0c6468a8230e1db229cff8029217cf623c767ea5d60bfbd42729ea54d5"
 "checksum unicode-normalization 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "51ccda9ef9efa3f7ef5d91e8f9b83bbe6955f9bf86aec89d5cce2c874625920f"

+ 1 - 1
Cargo.toml

@@ -34,7 +34,7 @@ natord = "1.0.7"
 num_cpus = "1.3.0"
 number_prefix = "0.2.3"
 scoped_threadpool = "0.1.*"
-term_grid = "0.1.2"
+term_grid = "0.1.6"
 unicode-width = "0.1.4"
 users = "0.5.2"
 term_size = "0.3.0"

+ 1 - 1
src/exa.rs

@@ -184,7 +184,7 @@ impl<'args, 'w, W: Write + 'w> Exa<'args, 'w, W> {
                 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 }.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),
             }
         }
         else {

+ 21 - 5
src/output/grid_details.rs

@@ -13,7 +13,6 @@ use output::cell::TextCell;
 use output::colours::Colours;
 use output::details::{Options as DetailsOptions, Row as DetailsRow, Render as DetailsRender};
 use output::grid::Options as GridOptions;
-use output::lines::Render as LinesRender;
 use output::file_name::FileStyle;
 use output::table::{Table, Row as TableRow, Options as TableOptions};
 use output::tree::{TreeParams, TreeDepth};
@@ -45,6 +44,10 @@ pub struct Render<'a> {
     /// render will already have been filtered and sorted, but any directories
     /// that we recurse into will have to have this applied.
     pub filter: &'a FileFilter,
+
+    /// The minimum number of rows that there need to be before grid-details
+    /// mode is activated.
+    pub row_threshold: Option<usize>,
 }
 
 impl<'a> Render<'a> {
@@ -67,13 +70,17 @@ impl<'a> Render<'a> {
         }
     }
 
-    /// Create a Lines render for when this grid-details render doesn’t fit
+    /// Create a Details render for when this grid-details render doesn’t fit
     /// in the terminal (or something has gone wrong) and we have given up.
-    pub fn lines(self) -> LinesRender<'a> {
-        LinesRender {
+    pub fn give_up(self) -> DetailsRender<'a> {
+        DetailsRender {
+            dir: self.dir,
             files: self.files,
             colours: self.colours,
             style: self.style,
+            opts: self.details,
+            recurse: None,
+            filter: &self.filter,
         }
     }
 
@@ -82,7 +89,7 @@ impl<'a> Render<'a> {
             write!(w, "{}", grid.fit_into_columns(width))
         }
         else {
-            self.lines().render(w)
+            self.give_up().render(w)
         }
     }
 
@@ -117,6 +124,15 @@ impl<'a> Render<'a> {
                 last_working_table = grid;
             }
             else {
+                // If we’ve figured out how many columns can fit in the user’s
+                // terminal, and it turns out there aren’t enough rows to
+                // make it worthwhile, then just resort to the lines view.
+                if let Some(thresh) = self.row_threshold {
+                    if last_working_table.fit_into_columns(column_count - 1).row_count() < thresh {
+                        return None;
+                    }
+                }
+
                 return Some((last_working_table, column_count - 1));
             }
         }