Merge pull request #836 from ariasuni/fix-exa-grid-rows

Fix `EXA_GRID_ROWS` not working in some cases
This commit is contained in:
Benjamin Sago 2021-04-09 23:02:49 +01:00 committed by GitHub
commit f3ae6a9bd9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 67 additions and 15 deletions

View File

@ -174,22 +174,21 @@ impl<'a> Render<'a> {
};
if the_grid_fits {
if column_count == file_names.len() {
return Some((grid, column_count));
} else {
last_working_grid = grid;
}
} else {
// If weve figured out how many columns can fit in the users
// terminal, and it turns out there arent enough rows to
// make it worthwhile, then just resort to the lines view.
last_working_grid = grid;
}
if !the_grid_fits || column_count == file_names.len() {
let last_column_count = if the_grid_fits { column_count } else { column_count - 1 };
// If weve figured out how many columns can fit in the users terminal,
// and it turns out there arent enough rows to make it worthwhile
// (according to EXA_GRID_ROWS), then just resort to the lines view.
if let RowThreshold::MinimumRows(thresh) = self.row_threshold {
if last_working_grid.fit_into_columns(column_count - 1).row_count() < thresh {
if last_working_grid.fit_into_columns(last_column_count).row_count() < thresh {
return None;
}
}
return Some((last_working_grid, column_count - 1));
return Some((last_working_grid, last_column_count));
}
}

View File

@ -81,19 +81,49 @@ 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 dont produce extra columns even if there place for more"
name = "COLUMNS=200 exa -lGh with one file dont 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" }
stdout = { file = "outputs/files_long_grid_header_1file.ansitxt" }
stderr = { empty = true }
status = 0
tags = [ 'env', 'long', 'grid' ]
[[cmd]]
name = "COLUMN=200 exa -lGh with several files dont produce extra columns even if there place for more"
name = "COLUMNS=200 exa -lGh with several files dont 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" }
stdout = { file = "outputs/files_long_grid_header_2files.ansitxt" }
stderr = { empty = true }
status = 0
tags = [ 'env', 'long', 'grid' ]
# check if EXA_GRID_ROWS is working
[[cmd]]
name = "COLUMNS=200 EXA_GRID_ROWS=2 exa -lG with three files produces a grid details of 1 column"
shell = "exa -lG /testcases/files/1_*"
environment = { COLUMNS = "200", EXA_GRID_ROWS = "2" }
stdout = { file = "outputs/files_long_grid_exa_grid_rows_2_3files.ansitxt" }
stderr = { empty = true }
status = 0
tags = [ 'env', 'long', 'grid' ]
[[cmd]]
name = "COLUMNS=200 EXA_GRID_ROWS=5 exa -lG with 15 files produces a grid details of 3 columns"
shell = "exa -lG /testcases/files/1*"
environment = { COLUMNS = "200", EXA_GRID_ROWS = "5" }
stdout = { file = "outputs/files_long_grid_exa_grid_rows_5_15files.ansitxt" }
stderr = { empty = true }
status = 0
tags = [ 'env', 'long', 'grid' ]
[[cmd]]
name = "COLUMNS=200 EXA_GRID_ROWS=6 exa -lG with 15 files produces a grid details of 1 column"
shell = "exa -lG /testcases/files/1*"
environment = { COLUMNS = "200", EXA_GRID_ROWS = "6" }
stdout = { file = "outputs/files_long_grid_exa_grid_rows_6_15files.ansitxt" }
stderr = { empty = true }
status = 0
tags = [ 'env', 'long', 'grid' ]

View File

@ -0,0 +1,3 @@
.rw-r--r-- 1 cassowary  1 Jan 12:34 /testcases/files/1_bytes
.rw-r--r-- 1.0k cassowary  1 Jan 12:34 /testcases/files/1_KiB
.rw-r--r-- 1.0M cassowary  1 Jan 12:34 /testcases/files/1_MiB

View File

@ -0,0 +1,5 @@
.rw-r--r-- 10 cassowary  1 Jan 12:34 /testcases/files/10_bytes .rw-r--r-- 12M cassowary  1 Jan 12:34 /testcases/files/11_MiB .rw-r--r-- 13k cassowary  1 Jan 12:34 /testcases/files/13_KiB
.rw-r--r-- 10k cassowary  1 Jan 12:34 /testcases/files/10_KiB .rw-r--r-- 12 cassowary  1 Jan 12:34 /testcases/files/12_bytes .rw-r--r-- 14M cassowary  1 Jan 12:34 /testcases/files/13_MiB
.rw-r--r-- 10M cassowary  1 Jan 12:34 /testcases/files/10_MiB .rw-r--r-- 12k cassowary  1 Jan 12:34 /testcases/files/12_KiB .rw-r--r-- 1 cassowary  1 Jan 12:34 /testcases/files/1_bytes
.rw-r--r-- 11 cassowary  1 Jan 12:34 /testcases/files/11_bytes .rw-r--r-- 13M cassowary  1 Jan 12:34 /testcases/files/12_MiB .rw-r--r-- 1.0k cassowary  1 Jan 12:34 /testcases/files/1_KiB
.rw-r--r-- 11k cassowary  1 Jan 12:34 /testcases/files/11_KiB .rw-r--r-- 13 cassowary  1 Jan 12:34 /testcases/files/13_bytes .rw-r--r-- 1.0M cassowary  1 Jan 12:34 /testcases/files/1_MiB

View File

@ -0,0 +1,15 @@
.rw-r--r-- 1 cassowary  1 Jan 12:34 /testcases/files/1_bytes
.rw-r--r-- 1.0k cassowary  1 Jan 12:34 /testcases/files/1_KiB
.rw-r--r-- 1.0M cassowary  1 Jan 12:34 /testcases/files/1_MiB
.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
.rw-r--r-- 10M cassowary  1 Jan 12:34 /testcases/files/10_MiB
.rw-r--r-- 11 cassowary  1 Jan 12:34 /testcases/files/11_bytes
.rw-r--r-- 11k cassowary  1 Jan 12:34 /testcases/files/11_KiB
.rw-r--r-- 12M cassowary  1 Jan 12:34 /testcases/files/11_MiB
.rw-r--r-- 12 cassowary  1 Jan 12:34 /testcases/files/12_bytes
.rw-r--r-- 12k cassowary  1 Jan 12:34 /testcases/files/12_KiB
.rw-r--r-- 13M cassowary  1 Jan 12:34 /testcases/files/12_MiB
.rw-r--r-- 13 cassowary  1 Jan 12:34 /testcases/files/13_bytes
.rw-r--r-- 13k cassowary  1 Jan 12:34 /testcases/files/13_KiB
.rw-r--r-- 14M cassowary  1 Jan 12:34 /testcases/files/13_MiB