Added --icons for oneline mode

This commit is contained in:
Alex Soderman 2018-04-01 19:00:27 -04:00
parent 5991bd4ab7
commit 68954f9142
4 changed files with 30 additions and 10 deletions

View File

@ -221,8 +221,8 @@ impl<'args, 'w, W: Write + 'w> Exa<'args, 'w, W> {
let View { ref mode, ref colours, ref style } = self.options.view; let View { ref mode, ref colours, ref style } = self.options.view;
match *mode { match *mode {
Mode::Lines => { Mode::Lines(ref opts) => {
let r = lines::Render { files, colours, style }; let r = lines::Render { files, colours, style, opts };
r.render(self.writer) r.render(self.writer)
} }

View File

@ -1,4 +1,4 @@
use output::{View, Mode, grid, details}; use output::{View, Mode, grid, details, lines};
use output::grid_details::{self, RowThreshold}; use output::grid_details::{self, RowThreshold};
use output::table::{TimeTypes, Environment, SizeFormat, Columns, Options as TableOptions}; use output::table::{TimeTypes, Environment, SizeFormat, Columns, Options as TableOptions};
use output::time::TimeFormat; use output::time::TimeFormat;
@ -52,7 +52,8 @@ impl Mode {
Err(Useless(&flags::ACROSS, true, &flags::ONE_LINE)) Err(Useless(&flags::ACROSS, true, &flags::ONE_LINE))
} }
else { else {
Ok(Mode::Lines) let lines = lines::Options { icons: matches.has(&flags::ICONS)? };
Ok(Mode::Lines(lines))
} }
} }
else if matches.has(&flags::TREE)? { else if matches.has(&flags::TREE)? {
@ -91,7 +92,8 @@ impl Mode {
Ok(Mode::Details(details)) Ok(Mode::Details(details))
} }
else { else {
Ok(Mode::Lines) let lines = lines::Options { icons: matches.has(&flags::ICONS)?, };
Ok(Mode::Lines(lines))
} }
} }
}; };
@ -520,6 +522,7 @@ mod test {
mod views { mod views {
use super::*; use super::*;
use output::grid::Options as GridOptions; use output::grid::Options as GridOptions;
use output::lines::Options as LineOptions;
// Default // Default
test!(empty: Mode <- [], None; Both => like Ok(Mode::Grid(_))); test!(empty: Mode <- [], None; Both => like Ok(Mode::Grid(_)));
@ -532,8 +535,9 @@ mod test {
test!(icons: Mode <- ["--icons"], None; Both => like Ok(Mode::Grid(GridOptions { across: _, console_width: _, icons: true}))); test!(icons: Mode <- ["--icons"], None; Both => like Ok(Mode::Grid(GridOptions { across: _, console_width: _, icons: true})));
// Lines views // Lines views
test!(lines: Mode <- ["--oneline"], None; Both => like Ok(Mode::Lines)); test!(lines: Mode <- ["--oneline"], None; Both => like Ok(Mode::Lines(LineOptions{ icons: _ })));
test!(prima: Mode <- ["-1"], None; Both => like Ok(Mode::Lines)); test!(prima: Mode <- ["-1"], None; Both => like Ok(Mode::Lines(LineOptions{ icons: _ })));
test!(line_icon: Mode <- ["-1", "--icons"], None; Both => like Ok(Mode::Lines(LineOptions { icons: true })));
// Details views // Details views
test!(long: Mode <- ["--long"], None; Both => like Ok(Mode::Details(_))); test!(long: Mode <- ["--long"], None; Both => like Ok(Mode::Details(_)));

View File

@ -1,24 +1,40 @@
use std::io::{Write, Result as IOResult}; use std::io::{Write, Result as IOResult};
use ansi_term::ANSIStrings; use ansi_term::{ANSIStrings, ANSIGenericString};
use fs::File; use fs::File;
use output::file_name::{FileName, FileStyle}; use output::file_name::{FileName, FileStyle};
use style::Colours; use style::Colours;
use output::icons::painted_icon;
use output::cell::TextCell;
#[derive(PartialEq, Debug, Copy, Clone)]
pub struct Options {
pub icons: bool
}
/// The lines view literally just displays each file, line-by-line. /// The lines view literally just displays each file, line-by-line.
pub struct Render<'a> { pub struct Render<'a> {
pub files: Vec<File<'a>>, pub files: Vec<File<'a>>,
pub colours: &'a Colours, pub colours: &'a Colours,
pub style: &'a FileStyle, pub style: &'a FileStyle,
pub opts: &'a Options,
} }
impl<'a> Render<'a> { impl<'a> Render<'a> {
pub fn render<W: Write>(&self, w: &mut W) -> IOResult<()> { pub fn render<W: Write>(&self, w: &mut W) -> IOResult<()> {
for file in &self.files { for file in &self.files {
let name_cell = self.render_file(file).paint(); let name_cell = self.render_file(file).paint();
writeln!(w, "{}", ANSIStrings(&name_cell))?; if self.opts.icons {
// Create a TextCell for the icon then append the text to it
let mut cell = TextCell::default();
let icon = painted_icon(&file, self.style);
cell.push(ANSIGenericString::from(icon), 2);
cell.append(name_cell.promote());
writeln!(w, "{}", ANSIStrings(&cell))?;
} else {
writeln!(w, "{}", ANSIStrings(&name_cell))?;
}
} }
Ok(()) Ok(())

View File

@ -34,5 +34,5 @@ pub enum Mode {
Grid(grid::Options), Grid(grid::Options),
Details(details::Options), Details(details::Options),
GridDetails(grid_details::Options), GridDetails(grid_details::Options),
Lines, Lines(lines::Options),
} }