From 5991bd4ab7a7299c58aceb8ee0339aef0164f16b Mon Sep 17 00:00:00 2001 From: Alex Soderman <5639572+asoderman@users.noreply.github.com> Date: Sun, 1 Apr 2018 18:28:31 -0400 Subject: [PATCH] Added icons for --long view --- src/options/view.rs | 3 +++ src/output/details.rs | 29 +++++++++++++++++++++++------ 2 files changed, 26 insertions(+), 6 deletions(-) diff --git a/src/options/view.rs b/src/options/view.rs index 5fb45a7..790cb1c 100644 --- a/src/options/view.rs +++ b/src/options/view.rs @@ -40,6 +40,7 @@ impl Mode { table: Some(TableOptions::deduce(matches)?), header: matches.has(&flags::HEADER)?, xattr: xattr::ENABLED && matches.has(&flags::EXTENDED)?, + icons: matches.has(&flags::ICONS)?, }) } }; @@ -59,6 +60,7 @@ impl Mode { table: None, header: false, xattr: xattr::ENABLED && matches.has(&flags::EXTENDED)?, + icons: matches.has(&flags::ICONS)?, }; Ok(Mode::Details(details)) @@ -83,6 +85,7 @@ impl Mode { table: None, header: false, xattr: xattr::ENABLED && matches.has(&flags::EXTENDED)?, + icons: matches.has(&flags::ICONS)?, }; Ok(Mode::Details(details)) diff --git a/src/output/details.rs b/src/output/details.rs index 3a81a76..a103cb3 100644 --- a/src/output/details.rs +++ b/src/output/details.rs @@ -64,7 +64,7 @@ use std::io::{Write, Error as IOError, Result as IOResult}; use std::path::PathBuf; use std::vec::IntoIter as VecIntoIter; -use ansi_term::Style; +use ansi_term::{ANSIGenericString, Style}; use fs::{Dir, File}; use fs::dir_action::RecurseOptions; @@ -77,6 +77,7 @@ use output::cell::TextCell; use output::tree::{TreeTrunk, TreeParams, TreeDepth}; use output::file_name::FileStyle; use output::table::{Table, Options as TableOptions, Row as TableRow}; +use output::icons::painted_icon; use scoped_threadpool::Pool; @@ -105,6 +106,9 @@ pub struct Options { /// Whether to show each file's extended attributes. pub xattr: bool, + + /// Enables --icons mode + pub icons: bool, } @@ -132,6 +136,7 @@ struct Egg<'a> { errors: Vec<(IOError, Option)>, dir: Option, file: &'a File<'a>, + icon: Option, } impl<'a> AsRef> for Egg<'a> { @@ -195,7 +200,7 @@ impl<'a> Render<'a> { let table = table.as_ref(); for file in src { - let file_eggs = file_eggs.clone(); + let file_eggs = Arc::clone(&file_eggs); scoped.execute(move || { let mut errors = Vec::new(); @@ -256,7 +261,11 @@ impl<'a> Render<'a> { } }; - let egg = Egg { table_row, xattrs, errors, dir, file }; + let icon = if self.opts.icons { + Some(painted_icon(&file, &self.style)) + } else { None }; + + let egg = Egg { table_row, xattrs, errors, dir, file, icon }; file_eggs.lock().unwrap().push(egg); }); } @@ -272,12 +281,20 @@ impl<'a> Render<'a> { t.add_widths(row); } + let mut name_cell = TextCell::default(); + if let Some(icon) = egg.icon { + name_cell.push(ANSIGenericString::from(icon), 2) + } + name_cell.append(self.style.for_file(&egg.file, self.colours) + .with_link_paths() + .paint() + .promote()); + + let row = Row { tree: tree_params, cells: egg.table_row, - name: self.style.for_file(&egg.file, self.colours) - .with_link_paths() - .paint().promote(), + name: name_cell, }; rows.push(row);