Skip to content

Commit 0f414cf

Browse files
committed
Don’t produce extra column sometimes with long grid + header
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.
1 parent 73e43c0 commit 0f414cf

File tree

4 files changed

+39
-7
lines changed

4 files changed

+39
-7
lines changed

src/output/grid_details.rs

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,11 @@ impl<'a> Render<'a> {
157157
.map(|file| self.file_style.for_file(file, self.theme).paint().promote())
158158
.collect::<Vec<_>>();
159159

160-
let mut last_working_table = self.make_grid(1, options, &file_names, rows.clone(), &drender);
160+
let mut last_working_grid = self.make_grid(1, options, &file_names, rows.clone(), &drender);
161+
162+
if file_names.len() == 1 {
163+
return Some((last_working_grid, 1));
164+
}
161165

162166
// If we can’t fit everything in a grid 100 columns wide, then
163167
// something has gone seriously awry
@@ -166,23 +170,26 @@ impl<'a> Render<'a> {
166170

167171
let the_grid_fits = {
168172
let d = grid.fit_into_columns(column_count);
169-
d.is_complete() && d.width() <= self.console_width
173+
d.width() <= self.console_width
170174
};
171175

172176
if the_grid_fits {
173-
last_working_table = grid;
174-
}
175-
else {
177+
if column_count == file_names.len() {
178+
return Some((grid, column_count));
179+
} else {
180+
last_working_grid = grid;
181+
}
182+
} else {
176183
// If we’ve figured out how many columns can fit in the user’s
177184
// terminal, and it turns out there aren’t enough rows to
178185
// make it worthwhile, then just resort to the lines view.
179186
if let RowThreshold::MinimumRows(thresh) = self.row_threshold {
180-
if last_working_table.fit_into_columns(column_count - 1).row_count() < thresh {
187+
if last_working_grid.fit_into_columns(column_count - 1).row_count() < thresh {
181188
return None;
182189
}
183190
}
184191

185-
return Some((last_working_table, column_count - 1));
192+
return Some((last_working_grid, column_count - 1));
186193
}
187194
}
188195

xtests/grid-details-view.toml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,3 +76,24 @@ stdout = { file = "outputs/files_paths_long_grid_3col.ansitxt" }
7676
stderr = { empty = true }
7777
status = 0
7878
tags = [ 'env', 'long', 'grid' ]
79+
80+
81+
# check if exa is using the minimum number of columns with headers
82+
83+
[[cmd]]
84+
name = "‘COLUMN=200 exa -lGh’ with one file don’t produce extra columns even if there place for more"
85+
shell = "exa -lGh /testcases/files/10_bytes"
86+
environment = { COLUMNS = "200" }
87+
stdout = { file = "outputs/files_paths_long_grid_header_1file.ansitxt" }
88+
stderr = { empty = true }
89+
status = 0
90+
tags = [ 'env', 'long', 'grid' ]
91+
92+
[[cmd]]
93+
name = "‘COLUMN=200 exa -lGh’ with several files don’t produce extra columns even if there place for more"
94+
shell = "exa -lGh /testcases/files/10_{bytes,KiB}"
95+
environment = { COLUMNS = "200" }
96+
stdout = { file = "outputs/files_paths_long_grid_header_2files.ansitxt" }
97+
stderr = { empty = true }
98+
status = 0
99+
tags = [ 'env', 'long', 'grid' ]
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Permissions Size User Date Modified Name
2+
.rw-r--r-- 10 cassowary  1 Jan 12:34 /testcases/files/10_bytes
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Permissions Size User Date Modified Name Permissions Size User Date Modified Name
2+
.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

0 commit comments

Comments
 (0)