ソースを参照

fix!: implement `EZA_GRID_ROWS` grid details view minimum rows threshold

Grid details view had been prevented only by console width being
unavailable.

This changeset implements `EZA_GRID_ROWS` as secondary grid details
inhibitor, preventing grid details view if the minimum rows threshold is
not reached by grid which would be rendered.

Fix:
https://github.com/eza-community/eza/issues/66#issuecomment-2198567463
Fix: #1044

BREAKING CHANGE: Before this change, the `EZA_GRID_ROWS` variable was
ignored, despite documentation existing. Users relying on `EZA_GRID_ROW`
not doing anything will find their output changed. For more info, see
LeoniePhiline 1 年間 前
コミット
97a8abe06e
1 ファイル変更37 行追加2 行削除
  1. 37 2
      src/output/grid_details.rs

+ 37 - 2
src/output/grid_details.rs

@@ -143,11 +143,11 @@ impl<'a> Render<'a> {
 
         let cells = rows
             .into_iter()
-            .zip(self.files)
+            .zip(&self.files)
             .map(|(row, file)| {
                 let filename = self
                     .file_style
-                    .for_file(&file, self.theme)
+                    .for_file(file, self.theme)
                     .paint()
                     .strings()
                     .to_string();
@@ -178,6 +178,41 @@ impl<'a> Render<'a> {
             },
         );
 
+        // If a minimum grid rows threshold has been set
+        // via the `EZA_GRID_ROWS` environment variable
+        // and the grid is going to get rendered with fewer rows,
+        // then render a details list view instead.
+        if let RowThreshold::MinimumRows(minimum_rows) = self.row_threshold {
+            if grid.row_count() < minimum_rows {
+                let Self {
+                    dir,
+                    files,
+                    theme,
+                    file_style,
+                    details: opts,
+                    filter,
+                    git_ignoring,
+                    git,
+                    git_repos,
+                    ..
+                } = self;
+
+                let r = DetailsRender {
+                    dir,
+                    files,
+                    theme,
+                    file_style,
+                    opts,
+                    recurse: None,
+                    filter,
+                    git_ignoring,
+                    git,
+                    git_repos,
+                };
+                return r.render(w);
+            }
+        }
+
         if self.details.header {
             let row = table.header_row();
             let name = TextCell::paint_str(self.theme.ui.header, "Name")