diff --git a/src/main.rs b/src/main.rs index 15fe464f6..4b21fc8f9 100644 --- a/src/main.rs +++ b/src/main.rs @@ -495,7 +495,6 @@ impl Exa<'_> { } (Mode::GridDetails(ref opts), Some(console_width)) => { - let details = &opts.details; let row_threshold = opts.row_threshold; let filter = &self.options.filter; @@ -508,7 +507,7 @@ impl Exa<'_> { files, theme, file_style, - details, + opts, filter, row_threshold, git_ignoring, diff --git a/src/options/view.rs b/src/options/view.rs index 18aedaf8d..6da241965 100644 --- a/src/options/view.rs +++ b/src/options/view.rs @@ -80,9 +80,11 @@ impl Mode { if flag.is_some() && flag.unwrap().matches(&flags::GRID) { let _ = matches.has(&flags::GRID)?; + let across = matches.has(&flags::ACROSS)?; let row_threshold = RowThreshold::deduce(vars)?; let grid_details = grid_details::Options { details, + across, row_threshold, }; return Ok(Self::GridDetails(grid_details)); @@ -772,6 +774,7 @@ mod test { use super::*; use crate::output::grid::Options as GridOptions; + use crate::output::grid_details::Options as GridDetailsOptions; // Default test_mode!(empty: <- [], None; Both => like Ok(Mode::Grid(_))); @@ -800,8 +803,10 @@ mod test { test_mode!(ell: <- ["-l"], None; Both => like Ok(Mode::Details(_))); // Grid-details views - test_mode!(lid: <- ["--long", "--grid"], None; Both => like Ok(Mode::GridDetails(_))); - test_mode!(leg: <- ["-lG"], None; Both => like Ok(Mode::GridDetails(_))); + test_mode!(lid: <- ["--long", "--grid"], None; Both => like Ok(Mode::GridDetails(GridDetailsOptions { across: false, .. }))); + test_mode!(leg: <- ["-lG"], None; Both => like Ok(Mode::GridDetails(GridDetailsOptions { across: false, .. }))); + + test_mode!(long_grid_across: <- ["--long", "--grid", "--across"], None; Both => like Ok(Mode::GridDetails(GridDetailsOptions { across: true, .. }))); // Options that do nothing with --long test_mode!(long_across: <- ["--long", "--across"], None; Last => like Ok(Mode::Details(_))); diff --git a/src/output/grid_details.rs b/src/output/grid_details.rs index 32d999734..d9720b953 100644 --- a/src/output/grid_details.rs +++ b/src/output/grid_details.rs @@ -25,6 +25,7 @@ use crate::theme::Theme; #[derive(PartialEq, Eq, Debug)] pub struct Options { pub details: DetailsOptions, + pub across: bool, pub row_threshold: RowThreshold, } @@ -33,6 +34,15 @@ impl Options { pub fn to_details_options(&self) -> &DetailsOptions { &self.details } + + #[must_use] + pub fn direction(&self) -> Direction { + if self.across { + Direction::LeftToRight + } else { + Direction::TopToBottom + } + } } /// The grid-details view can be configured to revert to just a details view @@ -67,8 +77,8 @@ pub struct Render<'a> { /// How to format filenames. pub file_style: &'a FileStyle, - /// The details part of the grid-details view. - pub details: &'a DetailsOptions, + /// Details and Sorting Options + pub opts: &'a Options, /// How to filter files after listing a directory. The files in this /// render will already have been filtered and sorted, but any directories @@ -104,7 +114,7 @@ impl<'a> Render<'a> { files: Vec::new(), theme: self.theme, file_style: self.file_style, - opts: self.details, + opts: self.opts.to_details_options(), recurse: None, filter: self.filter, git_ignoring: self.git_ignoring, @@ -118,7 +128,8 @@ impl<'a> Render<'a> { pub fn render(mut self, w: &mut W) -> io::Result<()> { let options = self - .details + .opts + .to_details_options() .table .as_ref() .expect("Details table options not given!"); @@ -126,7 +137,7 @@ impl<'a> Render<'a> { let drender = self.details_for_column(); let color_scale_info = ColorScaleInformation::from_color_scale( - self.details.color_scale, + self.opts.to_details_options().color_scale, &self.files, self.filter.dot_filter, self.git, @@ -167,7 +178,7 @@ impl<'a> Render<'a> { // Therefore we pad the filenames with some spaces. We have to // use ansi_width here, because the filename might contain some // styling. - let padding = " ".repeat(if self.details.header { + let padding = " ".repeat(if self.opts.to_details_options().header { 4usize.saturating_sub(ansi_width::ansi_width(&filename)) } else { 0 @@ -181,7 +192,7 @@ impl<'a> Render<'a> { cells, GridOptions { filling: Filling::Spaces(4), - direction: Direction::TopToBottom, + direction: self.opts.direction(), width: self.console_width, }, ); @@ -197,7 +208,7 @@ impl<'a> Render<'a> { files, theme, file_style, - details: opts, + opts, filter, git_ignoring, git, @@ -210,7 +221,7 @@ impl<'a> Render<'a> { files, theme, file_style, - opts, + opts: opts.to_details_options(), recurse: None, filter, git_ignoring, @@ -221,7 +232,7 @@ impl<'a> Render<'a> { } } - if self.details.header { + if self.opts.to_details_options().header { let row = table.header_row(); let name = TextCell::paint_str(self.theme.ui.header.unwrap_or_default(), "Name") .strings() @@ -260,7 +271,7 @@ impl<'a> Render<'a> { // The header row will be printed separately, but it should be // considered for the width calculations. - if self.details.header { + if self.opts.to_details_options().header { let row = table.header_row(); table.add_widths(&row); }