diff --git a/src/main.rs b/src/main.rs index 0e2fbbb0af36fdb51cef1858a20c7a3ba57d86a1..ad1a7977b669ba8ab715e9b5849033edeeca9381 100644 --- a/src/main.rs +++ b/src/main.rs @@ -268,14 +268,9 @@ impl<'args> Exa<'args> { r.render(&mut self.writer) } - (Mode::Grid(ref opts), None) => { - let opts = &opts.to_lines_options(); - let r = lines::Render { files, theme, file_style, opts }; - r.render(&mut self.writer) - } - - (Mode::Lines(ref opts), _) => { - let r = lines::Render { files, theme, file_style, opts }; + (Mode::Grid(_), None) | + (Mode::Lines, _) => { + let r = lines::Render { files, theme, file_style }; r.render(&mut self.writer) } diff --git a/src/options/file_name.rs b/src/options/file_name.rs index 9092b8c935ed51d175610d2700caf04fc573cc85..283562a72bd7b536a21dc5d7e4fa7fc217405e18 100644 --- a/src/options/file_name.rs +++ b/src/options/file_name.rs @@ -6,8 +6,10 @@ use crate::output::file_name::{Options, Classify}; impl Options { pub fn deduce(matches: &MatchedFlags<'_>) -> Result { - Classify::deduce(matches) - .map(|classify| Self { classify }) + let classify = Classify::deduce(matches)?; + let icons = matches.has(&flags::ICONS)?; + + Ok(Self { classify, icons }) } } diff --git a/src/options/view.rs b/src/options/view.rs index b9b38ba9be63664b2abca9d90c7faaef2dfeccc5..bb97286c0e9772efb91c281b3a60e99282edbfa3 100644 --- a/src/options/view.rs +++ b/src/options/view.rs @@ -1,7 +1,7 @@ use crate::fs::feature::xattr; use crate::options::{flags, OptionsError, Vars}; use crate::options::parser::MatchedFlags; -use crate::output::{View, Mode, TerminalWidth, grid, details, lines}; +use crate::output::{View, Mode, TerminalWidth, grid, details}; use crate::output::grid_details::{self, RowThreshold}; use crate::output::file_name::Options as FileStyle; use crate::output::table::{TimeTypes, SizeFormat, Columns, Options as TableOptions}; @@ -73,8 +73,7 @@ impl Mode { if flag.matches(&flags::ONE_LINE) { let _ = matches.has(&flags::ONE_LINE)?; - let lines = lines::Options::deduce(matches)?; - return Ok(Self::Lines(lines)); + return Ok(Self::Lines); } let grid = grid::Options::deduce(matches)?; @@ -105,19 +104,10 @@ impl Mode { } -impl lines::Options { - fn deduce(matches: &MatchedFlags<'_>) -> Result { - let lines = lines::Options { icons: matches.has(&flags::ICONS)? }; - Ok(lines) - } -} - - impl grid::Options { fn deduce(matches: &MatchedFlags<'_>) -> Result { let grid = grid::Options { across: matches.has(&flags::ACROSS)?, - icons: matches.has(&flags::ICONS)?, }; Ok(grid) @@ -131,7 +121,6 @@ impl details::Options { table: None, header: false, xattr: xattr::ENABLED && matches.has(&flags::EXTENDED)?, - icons: matches.has(&flags::ICONS)?, }; Ok(details) @@ -151,7 +140,6 @@ impl details::Options { table: Some(TableOptions::deduce(matches, vars)?), header: matches.has(&flags::HEADER)?, xattr: xattr::ENABLED && matches.has(&flags::EXTENDED)?, - icons: matches.has(&flags::ICONS)?, }) } } @@ -354,7 +342,7 @@ mod test { static TEST_ARGS: &[&Arg] = &[ &flags::BINARY, &flags::BYTES, &flags::TIME_STYLE, &flags::TIME, &flags::MODIFIED, &flags::CHANGED, - &flags::CREATED, &flags::ACCESSED, &flags::ICONS, + &flags::CREATED, &flags::ACCESSED, &flags::HEADER, &flags::GROUP, &flags::INODE, &flags::GIT, &flags::LINKS, &flags::BLOCKS, &flags::LONG, &flags::LEVEL, &flags::GRID, &flags::ACROSS, &flags::ONE_LINE, &flags::TREE ]; @@ -532,7 +520,6 @@ mod test { use super::*; use crate::output::grid::Options as GridOptions; - use crate::output::lines::Options as LineOptions; // Default @@ -543,12 +530,10 @@ mod test { test!(grid: Mode <- ["--grid"], None; Both => like Ok(Mode::Grid(GridOptions { across: false, .. }))); test!(across: Mode <- ["--across"], None; Both => like Ok(Mode::Grid(GridOptions { across: true, .. }))); test!(gracross: Mode <- ["-xG"], None; Both => like Ok(Mode::Grid(GridOptions { across: true, .. }))); - test!(icons: Mode <- ["--icons"], None; Both => like Ok(Mode::Grid(GridOptions { icons: true, .. }))); // Lines views - test!(lines: Mode <- ["--oneline"], None; Both => like Ok(Mode::Lines(LineOptions { .. }))); - test!(prima: Mode <- ["-1"], None; Both => like Ok(Mode::Lines(LineOptions { .. }))); - test!(line_icon: Mode <- ["-1", "--icons"], None; Both => like Ok(Mode::Lines(LineOptions { icons: true }))); + test!(lines: Mode <- ["--oneline"], None; Both => like Ok(Mode::Lines)); + test!(prima: Mode <- ["-1"], None; Both => like Ok(Mode::Lines)); // Details views test!(long: Mode <- ["--long"], None; Both => like Ok(Mode::Details(_))); @@ -585,7 +570,7 @@ mod test { test!(just_git_2: Mode <- ["--git"], None; Complain => err OptionsError::Useless(&flags::GIT, false, &flags::LONG)); // Contradictions and combinations - test!(lgo: Mode <- ["--long", "--grid", "--oneline"], None; Both => like Ok(Mode::Lines(_))); + test!(lgo: Mode <- ["--long", "--grid", "--oneline"], None; Both => like Ok(Mode::Lines)); test!(lgt: Mode <- ["--long", "--grid", "--tree"], None; Both => like Ok(Mode::Details(_))); test!(tgl: Mode <- ["--tree", "--grid", "--long"], None; Both => like Ok(Mode::GridDetails(_))); test!(tlg: Mode <- ["--tree", "--long", "--grid"], None; Both => like Ok(Mode::GridDetails(_))); diff --git a/src/output/details.rs b/src/output/details.rs index a3a33ce00b0e0145c19a341740d2a8243daa684d..10f2404d96da2c3dfbc9020dd3c8fdfb60a89956 100644 --- a/src/output/details.rs +++ b/src/output/details.rs @@ -106,9 +106,6 @@ pub struct Options { /// Whether to show each file’s extended attributes. pub xattr: bool, - - /// Whether icons mode is enabled. - pub icons: bool, } @@ -269,8 +266,8 @@ impl<'a> Render<'a> { } }; - let icon = if self.opts.icons { Some(painted_icon(file, self.theme)) } - else { None }; + let icon = if self.file_style.icons { Some(painted_icon(file, self.theme)) } + else { None }; let egg = Egg { table_row, xattrs, errors, dir, file, icon }; unsafe { std::ptr::write(file_eggs.lock().unwrap()[idx].as_mut_ptr(), egg) } diff --git a/src/output/file_name.rs b/src/output/file_name.rs index 0165f062a51eb5f388f934759467c29f14a56fb6..70bdca81be05123209e0432037c67bfb93f1ce2d 100644 --- a/src/output/file_name.rs +++ b/src/output/file_name.rs @@ -16,7 +16,8 @@ pub struct Options { /// Whether to append file class characters to file names. pub classify: Classify, - // todo: put icons here + /// Whether to prepend icon characters before file names. + pub icons: bool, } impl Options { @@ -142,6 +143,7 @@ impl<'a, 'dir, C: Colours> FileName<'a, 'dir, C> { if ! target.name.is_empty() { let target_options = Options { classify: Classify::JustFilenames, + icons: false, }; let target = FileName { diff --git a/src/output/grid.rs b/src/output/grid.rs index f03274465192e6db666a6e8704e1bcddd6196cf2..79d03db10c9dac6fefd0f26be0e9af01476d5b96 100644 --- a/src/output/grid.rs +++ b/src/output/grid.rs @@ -6,14 +6,12 @@ use crate::fs::File; use crate::output::cell::DisplayWidth; use crate::output::file_name::Options as FileStyle; use crate::output::icons::painted_icon; -use crate::output::lines; use crate::theme::Theme; #[derive(PartialEq, Debug, Copy, Clone)] pub struct Options { pub across: bool, - pub icons: bool, } impl Options { @@ -21,12 +19,6 @@ impl Options { if self.across { tg::Direction::LeftToRight } else { tg::Direction::TopToBottom } } - - pub fn to_lines_options(self) -> lines::Options { - lines::Options { - icons: self.icons - } - } } @@ -48,13 +40,13 @@ impl<'a> Render<'a> { grid.reserve(self.files.len()); for file in &self.files { - let icon = if self.opts.icons { Some(painted_icon(file, self.theme)) } - else { None }; + let icon = if self.file_style.icons { Some(painted_icon(file, self.theme)) } + else { None }; let filename = self.file_style.for_file(file, self.theme).paint(); - let width = if self.opts.icons { DisplayWidth::from(2) + filename.width() } - else { filename.width() }; + let width = if self.file_style.icons { DisplayWidth::from(2) + filename.width() } + else { filename.width() }; grid.add(tg::Cell { contents: format!("{}{}", &icon.unwrap_or_default(), filename.strings()), @@ -70,7 +62,7 @@ impl<'a> Render<'a> { // This isn’t *quite* the same as the lines view, which also // displays full link paths. for file in &self.files { - if self.opts.icons { + if self.file_style.icons { write!(w, "{}", painted_icon(file, self.theme))?; } diff --git a/src/output/grid_details.rs b/src/output/grid_details.rs index c52352c6f3b8a455909b4e7fbe178e0b274e0f12..c1a120370ab55b1cc656681135a6e434505efcf5 100644 --- a/src/output/grid_details.rs +++ b/src/output/grid_details.rs @@ -156,7 +156,7 @@ impl<'a> Render<'a> { let file_names = self.files.iter() .map(|file| { - if self.details.icons { + if self.file_style.icons { let mut icon_cell = TextCell::default(); icon_cell.push(ANSIGenericString::from(painted_icon(file, self.theme)), 2); let file_cell = self.file_style.for_file(file, self.theme).paint().promote(); diff --git a/src/output/lines.rs b/src/output/lines.rs index 58690314ca1aebd90d11fc5b9c4f8d432772af95..5b492caa58ae5a0709b83879cafc81491fb4eabc 100644 --- a/src/output/lines.rs +++ b/src/output/lines.rs @@ -9,24 +9,18 @@ use crate::output::icons::painted_icon; use crate::theme::Theme; -#[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 theme: &'a Theme, pub file_style: &'a FileStyle, - pub opts: &'a Options, } impl<'a> Render<'a> { pub fn render(&self, w: &mut W) -> io::Result<()> { for file in &self.files { let name_cell = self.render_file(file); - if self.opts.icons { + if self.file_style.icons { // Create a TextCell for the icon then append the text to it let mut cell = TextCell::default(); let icon = painted_icon(file, self.theme); diff --git a/src/output/mod.rs b/src/output/mod.rs index 14b4f15e9254e686de19f051f0651456912a4579..0361d128e906d090c2510e24b3651e7258add0b9 100644 --- a/src/output/mod.rs +++ b/src/output/mod.rs @@ -32,7 +32,7 @@ pub enum Mode { Grid(grid::Options), Details(details::Options), GridDetails(grid_details::Options), - Lines(lines::Options), + Lines, }