From de489fb8ac8376fa1c3ec5d85c85b125acaf99ee Mon Sep 17 00:00:00 2001 From: LeoniePhiline <22329650+LeoniePhiline@users.noreply.github.com> Date: Thu, 4 Jul 2024 21:10:38 +0200 Subject: [PATCH] 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. Fixes complaint at https://github.com/eza-community/eza/issues/66#issuecomment-2198567463 --- src/output/grid_details.rs | 39 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 37 insertions(+), 2 deletions(-) diff --git a/src/output/grid_details.rs b/src/output/grid_details.rs index 71c6bb8bb..03b24602d 100644 --- a/src/output/grid_details.rs +++ b/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")