Skip to content

Commit

Permalink
fix: implement EZA_GRID_ROWS grid details view minimum rows threshold
Browse files Browse the repository at this point in the history
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 the number of files matched.

Fixes complaint at #66 (comment)
  • Loading branch information
LeoniePhiline committed Jul 1, 2024
1 parent d414d4b commit 09f64d1
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 48 deletions.
106 changes: 62 additions & 44 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -443,52 +443,70 @@ impl<'args> Exa<'args> {
r.render(&mut self.writer)
}

(Mode::GridDetails(ref opts), Some(console_width)) => {
let details = &opts.details;
let row_threshold = opts.row_threshold;

let filter = &self.options.filter;
let git_ignoring = self.options.filter.git_ignore == GitIgnore::CheckAndIgnore;
let git = self.git.as_ref();
let git_repos = self.git_repos;

let r = grid_details::Render {
dir,
files,
theme,
file_style,
details,
filter,
row_threshold,
git_ignoring,
git,
console_width,
git_repos,
(Mode::GridDetails(ref opts), console_width) => {
// Grid details view is prevented if minimum rows are required,
// but fewer files than the defined threshold are to be rendered.
//
// This option is set by the `EZA_GRID_ROWS` environment variable.
let row_threshold_prevents_grid = match opts.row_threshold {
grid_details::RowThreshold::AlwaysGrid => false,
grid_details::RowThreshold::MinimumRows(minimum_rows) => {
files.len() < minimum_rows
}
};
r.render(&mut self.writer)
}

(Mode::GridDetails(ref opts), None) => {
let opts = &opts.to_details_options();
let filter = &self.options.filter;
let recurse = self.options.dir_action.recurse_options();
let git_ignoring = self.options.filter.git_ignore == GitIgnore::CheckAndIgnore;
let git = self.git.as_ref();
let git_repos = self.git_repos;

let r = details::Render {
dir,
files,
theme,
file_style,
opts,
recurse,
filter,
git_ignoring,
git,
git_repos,
};
r.render(&mut self.writer)
// Console width is available,
// and grid view is not prevented by a minimum rows threshold.
//
// -> Render grid details view.
if let (false, Some(console_width)) = (row_threshold_prevents_grid, console_width) {
let details = &opts.details;

let filter = &self.options.filter;
let git_ignoring = self.options.filter.git_ignore == GitIgnore::CheckAndIgnore;
let git = self.git.as_ref();
let git_repos = self.git_repos;

let r = grid_details::Render {
dir,
files,
theme,
file_style,
details,
filter,
git_ignoring,
git,
console_width,
git_repos,
};
r.render(&mut self.writer)
} else {
// Console width is unavailable,
// or grid view minimum rows threshold prevents grid view.
//
// -> Force details list view.

let opts = &opts.to_details_options();
let filter = &self.options.filter;
let recurse = self.options.dir_action.recurse_options();
let git_ignoring = self.options.filter.git_ignore == GitIgnore::CheckAndIgnore;
let git = self.git.as_ref();
let git_repos = self.git_repos;

let r = details::Render {
dir,
files,
theme,
file_style,
opts,
recurse,
filter,
git_ignoring,
git,
git_repos,
};
r.render(&mut self.writer)
}
}
}
}
Expand Down
4 changes: 0 additions & 4 deletions src/output/grid_details.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,6 @@ pub struct Render<'a> {
/// 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: RowThreshold,

/// Whether we are skipping Git-ignored files.
pub git_ignoring: bool,

Expand Down

0 comments on commit 09f64d1

Please sign in to comment.