Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -508,7 +507,7 @@ impl Exa<'_> {
files,
theme,
file_style,
details,
opts,
filter,
row_threshold,
git_ignoring,
Expand Down
9 changes: 7 additions & 2 deletions src/options/view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down Expand Up @@ -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(_)));
Expand Down Expand Up @@ -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(_)));
Expand Down
33 changes: 22 additions & 11 deletions src/output/grid_details.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}

Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand All @@ -118,15 +128,16 @@ impl<'a> Render<'a> {

pub fn render<W: Write>(mut self, w: &mut W) -> io::Result<()> {
let options = self
.details
.opts
.to_details_options()
.table
.as_ref()
.expect("Details table options not given!");

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,
Expand Down Expand Up @@ -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
Expand All @@ -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,
},
);
Expand All @@ -197,7 +208,7 @@ impl<'a> Render<'a> {
files,
theme,
file_style,
details: opts,
opts,
filter,
git_ignoring,
git,
Expand All @@ -210,7 +221,7 @@ impl<'a> Render<'a> {
files,
theme,
file_style,
opts,
opts: opts.to_details_options(),
recurse: None,
filter,
git_ignoring,
Expand All @@ -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()
Expand Down Expand Up @@ -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);
}
Expand Down
Loading