mirror of
https://github.com/Llewellynvdm/exa.git
synced 2024-11-22 12:05:11 +00:00
Only engage the view when there are files to show
This changes the way that views are used to display the actual lists of files. It used to pass empty vectors to the view methods, which most of the time would not print anything because there are no files to list — except when there’s a header row which gets printed for no files. By not calling the view method at all when there’s nothing to print, exa won’t ever print extra things in the view unless it needs to for a file. This fixes #106 “Don’t print the header if the result set is empty”
This commit is contained in:
parent
54067bf765
commit
a7e3456b0d
26
src/exa.rs
26
src/exa.rs
@ -95,10 +95,7 @@ impl<'w, W: Write + 'w> Exa<'w, W> {
|
|||||||
let no_files = files.is_empty();
|
let no_files = files.is_empty();
|
||||||
let is_only_dir = dirs.len() == 1 && no_files;
|
let is_only_dir = dirs.len() == 1 && no_files;
|
||||||
|
|
||||||
if !no_files {
|
try!(self.print_files(None, files));
|
||||||
try!(self.print_files(None, files));
|
|
||||||
}
|
|
||||||
|
|
||||||
self.print_dirs(dirs, no_files, is_only_dir)
|
self.print_dirs(dirs, no_files, is_only_dir)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -142,11 +139,7 @@ impl<'w, W: Write + 'w> Exa<'w, W> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try!(self.print_files(Some(&dir), children));
|
try!(self.print_files(Some(&dir), children));
|
||||||
|
try!(self.print_dirs(child_dirs, false, false));
|
||||||
if !child_dirs.is_empty() {
|
|
||||||
try!(self.print_dirs(child_dirs, false, false));
|
|
||||||
}
|
|
||||||
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -161,11 +154,16 @@ impl<'w, W: Write + 'w> Exa<'w, W> {
|
|||||||
/// For various annoying logistical reasons, each one handles
|
/// For various annoying logistical reasons, each one handles
|
||||||
/// printing differently...
|
/// printing differently...
|
||||||
fn print_files(&mut self, dir: Option<&Dir>, files: Vec<File>) -> IOResult<()> {
|
fn print_files(&mut self, dir: Option<&Dir>, files: Vec<File>) -> IOResult<()> {
|
||||||
match self.options.view {
|
if !files.is_empty() {
|
||||||
View::Grid(g) => g.view(&files, self.writer),
|
match self.options.view {
|
||||||
View::Details(d) => d.view(dir, files, self.writer),
|
View::Grid(g) => g.view(&files, self.writer),
|
||||||
View::GridDetails(gd) => gd.view(dir, files, self.writer),
|
View::Details(d) => d.view(dir, files, self.writer),
|
||||||
View::Lines(l) => l.view(files, self.writer),
|
View::GridDetails(gd) => gd.view(dir, files, self.writer),
|
||||||
|
View::Lines(l) => l.view(files, self.writer),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
0
xtests/empty
Normal file
0
xtests/empty
Normal file
@ -18,6 +18,8 @@ $exa $testcases/files -lh | diff -q - $results/files_lh || exit 1
|
|||||||
$exa $testcases/files -lhb | diff -q - $results/files_lhb || exit 1
|
$exa $testcases/files -lhb | diff -q - $results/files_lhb || exit 1
|
||||||
$exa $testcases/files -lhB | diff -q - $results/files_lhb2 || exit 1
|
$exa $testcases/files -lhB | diff -q - $results/files_lhb2 || exit 1
|
||||||
|
|
||||||
|
$exa $testcases/attributes/dirs/empty-with-attribute -lh | diff -q - $results/empty || exit 1
|
||||||
|
|
||||||
# Grid view tests
|
# Grid view tests
|
||||||
COLUMNS=40 $exa $testcases/files | diff -q - $results/files_40 || exit 1
|
COLUMNS=40 $exa $testcases/files | diff -q - $results/files_40 || exit 1
|
||||||
COLUMNS=80 $exa $testcases/files | diff -q - $results/files_80 || exit 1
|
COLUMNS=80 $exa $testcases/files | diff -q - $results/files_80 || exit 1
|
||||||
|
Loading…
Reference in New Issue
Block a user