mirror of
https://github.com/Llewellynvdm/exa.git
synced 2025-01-27 07:38:27 +00:00
Merge pull request #756 from whonore/fix-sort-arguments
Apply sort order to files in line and grid outputs
This commit is contained in:
commit
cf5070a20e
@ -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)
|
||||
}
|
||||
|
||||
|
@ -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();
|
||||
|
||||
|
@ -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))?;
|
||||
|
6
xtests/outputs/exts_grid_sort_name_reverse.ansitxt
Normal file
6
xtests/outputs/exts_grid_sort_name_reverse.ansitxt
Normal file
@ -0,0 +1,6 @@
|
||||
[38;5;135mvideo.wmv[0m [38;5;93mlossless.flac[0m [38;5;109mcrypto.signature[0m [31mcompressed.tar.gz[0m [38;5;244mbackup~[0m
|
||||
[38;5;135mVIDEO.AVI[0m [38;5;133mimage.svg[0m [38;5;109mcrypto.asc[0m [31mcompressed.deb[0m [38;5;244m#SAVEFILE#[0m
|
||||
[38;5;92mMUSIC.OGG[0m [38;5;133mIMAGE.PNG[0m [31mCOMPRESSED.ZIP[0m [38;5;137mcompiled.o[0m
|
||||
[38;5;92mmusic.mp3[0m [38;5;244mfile.tmp[0m [31mcompressed.txz[0m compiled.js
|
||||
[1;4;33mMakefile[0m [38;5;105mDOCUMENT.XLSX[0m [31mcompressed.tgz[0m compiled.coffee
|
||||
[38;5;93mlossless.wav[0m [38;5;105mdocument.pdf[0m [31mcompressed.tar.xz[0m [38;5;137mcompiled.class[0m
|
26
xtests/outputs/exts_oneline_sort_name_reverse.ansitxt
Normal file
26
xtests/outputs/exts_oneline_sort_name_reverse.ansitxt
Normal file
@ -0,0 +1,26 @@
|
||||
[38;5;135mvideo.wmv[0m
|
||||
[38;5;135mVIDEO.AVI[0m
|
||||
[38;5;92mMUSIC.OGG[0m
|
||||
[38;5;92mmusic.mp3[0m
|
||||
[1;4;33mMakefile[0m
|
||||
[38;5;93mlossless.wav[0m
|
||||
[38;5;93mlossless.flac[0m
|
||||
[38;5;133mimage.svg[0m
|
||||
[38;5;133mIMAGE.PNG[0m
|
||||
[38;5;244mfile.tmp[0m
|
||||
[38;5;105mDOCUMENT.XLSX[0m
|
||||
[38;5;105mdocument.pdf[0m
|
||||
[38;5;109mcrypto.signature[0m
|
||||
[38;5;109mcrypto.asc[0m
|
||||
[31mCOMPRESSED.ZIP[0m
|
||||
[31mcompressed.txz[0m
|
||||
[31mcompressed.tgz[0m
|
||||
[31mcompressed.tar.xz[0m
|
||||
[31mcompressed.tar.gz[0m
|
||||
[31mcompressed.deb[0m
|
||||
[38;5;137mcompiled.o[0m
|
||||
compiled.js
|
||||
compiled.coffee
|
||||
[38;5;137mcompiled.class[0m
|
||||
[38;5;244mbackup~[0m
|
||||
[38;5;244m#SAVEFILE#[0m
|
@ -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' ]
|
||||
|
Loading…
x
Reference in New Issue
Block a user