diff --git a/src/exa.rs b/src/exa.rs index 2316e9c..149c7dd 100644 --- a/src/exa.rs +++ b/src/exa.rs @@ -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; match *mode { - Mode::Lines => { - let r = lines::Render { files, colours, style }; + Mode::Lines(ref opts) => { + let r = lines::Render { files, colours, style, opts }; r.render(self.writer) } diff --git a/src/options/view.rs b/src/options/view.rs index 790cb1c..1156bbd 100644 --- a/src/options/view.rs +++ b/src/options/view.rs @@ -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::table::{TimeTypes, Environment, SizeFormat, Columns, Options as TableOptions}; use output::time::TimeFormat; @@ -52,7 +52,8 @@ impl Mode { Err(Useless(&flags::ACROSS, true, &flags::ONE_LINE)) } else { - Ok(Mode::Lines) + let lines = lines::Options { icons: matches.has(&flags::ICONS)? }; + Ok(Mode::Lines(lines)) } } else if matches.has(&flags::TREE)? { @@ -91,7 +92,8 @@ impl Mode { Ok(Mode::Details(details)) } 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 { use super::*; use output::grid::Options as GridOptions; + use output::lines::Options as LineOptions; // Default 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}))); // Lines views - test!(lines: Mode <- ["--oneline"], None; Both => like Ok(Mode::Lines)); - test!(prima: Mode <- ["-1"], 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(LineOptions{ icons: _ }))); + test!(line_icon: Mode <- ["-1", "--icons"], None; Both => like Ok(Mode::Lines(LineOptions { icons: true }))); // Details views test!(long: Mode <- ["--long"], None; Both => like Ok(Mode::Details(_))); diff --git a/src/output/lines.rs b/src/output/lines.rs index 31ed017..5326a5d 100644 --- a/src/output/lines.rs +++ b/src/output/lines.rs @@ -1,24 +1,40 @@ use std::io::{Write, Result as IOResult}; -use ansi_term::ANSIStrings; +use ansi_term::{ANSIStrings, ANSIGenericString}; use fs::File; use output::file_name::{FileName, FileStyle}; 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. pub struct Render<'a> { pub files: Vec>, pub colours: &'a Colours, pub style: &'a FileStyle, + pub opts: &'a Options, } impl<'a> Render<'a> { pub fn render(&self, w: &mut W) -> IOResult<()> { for file in &self.files { 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(()) diff --git a/src/output/mod.rs b/src/output/mod.rs index 1eb4b77..3ac4e5c 100644 --- a/src/output/mod.rs +++ b/src/output/mod.rs @@ -34,5 +34,5 @@ pub enum Mode { Grid(grid::Options), Details(details::Options), GridDetails(grid_details::Options), - Lines, + Lines(lines::Options), }