Skip to content

Commit

Permalink
Apply sort order to line and grid outputs. Fix #404
Browse files Browse the repository at this point in the history
  • Loading branch information
whonore committed Jan 14, 2021
1 parent 13b91cc commit 2708360
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
6 changes: 4 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
5 changes: 4 additions & 1 deletion src/output/grid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -26,17 +27,19 @@ 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),
});

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();

Expand Down
5 changes: 4 additions & 1 deletion src/output/lines.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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))?;
Expand Down

0 comments on commit 2708360

Please sign in to comment.