From 0f414cf0b9b75e948424ae153a50f6f2b489a63c Mon Sep 17 00:00:00 2001 From: ariasuni Date: Sun, 10 Jan 2021 16:52:49 +0100 Subject: [PATCH] =?UTF-8?q?Don=E2=80=99t=20produce=20extra=20column=20some?= =?UTF-8?q?times=20with=20long=20grid=20+=20header?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The number of necessary columns was computed by producing a grid in different sizes and see if all columns were used. However, if there was two files and we tried to fit them in a 3-column grid, it would produces three headers and all three columns would be used; when trying a 4-column grid, the two supplementary headers would fill the third column and the fourth would be empty; so 3 columns would be used. Now, when the grid fits into the terminal and the number of columns is exactly the number of files to display, it returns immediately instead of trying bigger grids. Fixes GH-436. --- src/output/grid_details.rs | 21 ++++++++++++------- xtests/grid-details-view.toml | 21 +++++++++++++++++++ ...files_paths_long_grid_header_1file.ansitxt | 2 ++ ...iles_paths_long_grid_header_2files.ansitxt | 2 ++ 4 files changed, 39 insertions(+), 7 deletions(-) create mode 100644 xtests/outputs/files_paths_long_grid_header_1file.ansitxt create mode 100644 xtests/outputs/files_paths_long_grid_header_2files.ansitxt diff --git a/src/output/grid_details.rs b/src/output/grid_details.rs index ba157c3..df8e53c 100644 --- a/src/output/grid_details.rs +++ b/src/output/grid_details.rs @@ -157,7 +157,11 @@ impl<'a> Render<'a> { .map(|file| self.file_style.for_file(file, self.theme).paint().promote()) .collect::>(); - let mut last_working_table = self.make_grid(1, options, &file_names, rows.clone(), &drender); + let mut last_working_grid = self.make_grid(1, options, &file_names, rows.clone(), &drender); + + if file_names.len() == 1 { + return Some((last_working_grid, 1)); + } // If we can’t fit everything in a grid 100 columns wide, then // something has gone seriously awry @@ -166,23 +170,26 @@ impl<'a> Render<'a> { let the_grid_fits = { let d = grid.fit_into_columns(column_count); - d.is_complete() && d.width() <= self.console_width + d.width() <= self.console_width }; if the_grid_fits { - last_working_table = grid; - } - else { + if column_count == file_names.len() { + return Some((grid, column_count)); + } else { + last_working_grid = grid; + } + } else { // If we’ve figured out how many columns can fit in the user’s // terminal, and it turns out there aren’t enough rows to // make it worthwhile, then just resort to the lines view. if let RowThreshold::MinimumRows(thresh) = self.row_threshold { - if last_working_table.fit_into_columns(column_count - 1).row_count() < thresh { + if last_working_grid.fit_into_columns(column_count - 1).row_count() < thresh { return None; } } - return Some((last_working_table, column_count - 1)); + return Some((last_working_grid, column_count - 1)); } } diff --git a/xtests/grid-details-view.toml b/xtests/grid-details-view.toml index c307e0c..a76ba15 100644 --- a/xtests/grid-details-view.toml +++ b/xtests/grid-details-view.toml @@ -76,3 +76,24 @@ stdout = { file = "outputs/files_paths_long_grid_3col.ansitxt" } stderr = { empty = true } status = 0 tags = [ 'env', 'long', 'grid' ] + + +# check if exa is using the minimum number of columns with headers + +[[cmd]] +name = "‘COLUMN=200 exa -lGh’ with one file don’t produce extra columns even if there place for more" +shell = "exa -lGh /testcases/files/10_bytes" +environment = { COLUMNS = "200" } +stdout = { file = "outputs/files_paths_long_grid_header_1file.ansitxt" } +stderr = { empty = true } +status = 0 +tags = [ 'env', 'long', 'grid' ] + +[[cmd]] +name = "‘COLUMN=200 exa -lGh’ with several files don’t produce extra columns even if there place for more" +shell = "exa -lGh /testcases/files/10_{bytes,KiB}" +environment = { COLUMNS = "200" } +stdout = { file = "outputs/files_paths_long_grid_header_2files.ansitxt" } +stderr = { empty = true } +status = 0 +tags = [ 'env', 'long', 'grid' ] diff --git a/xtests/outputs/files_paths_long_grid_header_1file.ansitxt b/xtests/outputs/files_paths_long_grid_header_1file.ansitxt new file mode 100644 index 0000000..569a56e --- /dev/null +++ b/xtests/outputs/files_paths_long_grid_header_1file.ansitxt @@ -0,0 +1,2 @@ +Permissions Size User Date Modified Name +.rw-r--r-- 10 cassowary  1 Jan 12:34 /testcases/files/10_bytes diff --git a/xtests/outputs/files_paths_long_grid_header_2files.ansitxt b/xtests/outputs/files_paths_long_grid_header_2files.ansitxt new file mode 100644 index 0000000..dd566b9 --- /dev/null +++ b/xtests/outputs/files_paths_long_grid_header_2files.ansitxt @@ -0,0 +1,2 @@ +Permissions Size User Date Modified Name Permissions Size User Date Modified Name +.rw-r--r-- 10 cassowary  1 Jan 12:34 /testcases/files/10_bytes .rw-r--r-- 10k cassowary  1 Jan 12:34 /testcases/files/10_KiB