Merge pull request #756 from whonore/fix-sort-arguments

Apply sort order to files in line and grid outputs
This commit is contained in:
Benjamin Sago 2021-03-29 22:58:03 +01:00 committed by GitHub
commit cf5070a20e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 63 additions and 4 deletions

View File

@ -264,13 +264,15 @@ impl<'args> Exa<'args> {
match (mode, self.console_width) {
(Mode::Grid(ref opts), Some(console_width)) => {
let r = grid::Render { files, theme, file_style, opts, console_width };
let filter = &self.options.filter;
let r = grid::Render { files, theme, file_style, opts, console_width, filter };
r.render(&mut self.writer)
}
(Mode::Grid(_), None) |
(Mode::Lines, _) => {
let r = lines::Render { files, theme, file_style };
let filter = &self.options.filter;
let r = lines::Render { files, theme, file_style, filter };
r.render(&mut self.writer)
}

View File

@ -3,6 +3,7 @@ use std::io::{self, Write};
use term_grid as tg;
use crate::fs::File;
use crate::fs::filter::FileFilter;
use crate::output::file_name::Options as FileStyle;
use crate::theme::Theme;
@ -26,10 +27,11 @@ pub struct Render<'a> {
pub file_style: &'a FileStyle,
pub opts: &'a Options,
pub console_width: usize,
pub filter: &'a FileFilter,
}
impl<'a> Render<'a> {
pub fn render<W: Write>(&self, w: &mut W) -> io::Result<()> {
pub fn render<W: Write>(mut self, w: &mut W) -> io::Result<()> {
let mut grid = tg::Grid::new(tg::GridOptions {
direction: self.opts.direction(),
filling: tg::Filling::Spaces(2),
@ -37,6 +39,7 @@ impl<'a> Render<'a> {
grid.reserve(self.files.len());
self.filter.sort_files(&mut self.files);
for file in &self.files {
let filename = self.file_style.for_file(file, self.theme).paint();

View File

@ -3,6 +3,7 @@ use std::io::{self, Write};
use ansi_term::ANSIStrings;
use crate::fs::File;
use crate::fs::filter::FileFilter;
use crate::output::cell::TextCellContents;
use crate::output::file_name::{Options as FileStyle};
use crate::theme::Theme;
@ -13,10 +14,12 @@ pub struct Render<'a> {
pub files: Vec<File<'a>>,
pub theme: &'a Theme,
pub file_style: &'a FileStyle,
pub filter: &'a FileFilter,
}
impl<'a> Render<'a> {
pub fn render<W: Write>(&self, w: &mut W) -> io::Result<()> {
pub fn render<W: Write>(mut self, w: &mut W) -> io::Result<()> {
self.filter.sort_files(&mut self.files);
for file in &self.files {
let name_cell = self.render_file(file);
writeln!(w, "{}", ANSIStrings(&name_cell))?;

View File

@ -0,0 +1,6 @@
video.wmv lossless.flac crypto.signature compressed.tar.gz backup~
VIDEO.AVI image.svg crypto.asc compressed.deb #SAVEFILE#
MUSIC.OGG IMAGE.PNG COMPRESSED.ZIP compiled.o
music.mp3 file.tmp compressed.txz compiled.js
Makefile DOCUMENT.XLSX compressed.tgz compiled.coffee
lossless.wav document.pdf compressed.tar.xz compiled.class

View File

@ -0,0 +1,26 @@
video.wmv
VIDEO.AVI
MUSIC.OGG
music.mp3
Makefile
lossless.wav
lossless.flac
image.svg
IMAGE.PNG
file.tmp
DOCUMENT.XLSX
document.pdf
crypto.signature
crypto.asc
COMPRESSED.ZIP
compressed.txz
compressed.tgz
compressed.tar.xz
compressed.tar.gz
compressed.deb
compiled.o
compiled.js
compiled.coffee
compiled.class
backup~
#SAVEFILE#

View File

@ -136,3 +136,22 @@ stdout = { string = "plum\npear\npeach" }
stderr = { empty = true }
status = 0
tags = [ 'oneline', 'sort', 'dates' ]
# sorting with arguments specified
[[cmd]]
name = "exa -G --sort=name -r with file arguments sorts by file name in reverse order"
shell = "cd /testcases/file-names-exts; exa -G --sort=name -r *"
environment = { COLUMNS = "80" }
stdout = { file = "outputs/exts_grid_sort_name_reverse.ansitxt" }
stderr = { empty = true }
status = 0
tags = [ 'grid', 'sort', 'reverse' ]
[[cmd]]
name = "exa -1 --sort=name -r with file arguments sorts by file name in reverse order"
shell = "cd /testcases/file-names-exts; exa -1 --sort=name -r *"
stdout = { file = "outputs/exts_oneline_sort_name_reverse.ansitxt" }
stderr = { empty = true }
status = 0
tags = [ 'oneline', 'sort', 'reverse' ]