summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBenjamin Sago <ogham@bsago.me>2020-10-23 23:57:10 +0100
committerBenjamin Sago <ogham@bsago.me>2020-10-23 23:57:10 +0100
commita1869f208e0e9141e8668e64b0742ddd139da9fa (patch)
treee831f6267dfa3b132fe5f084c7a3dc351ee39a8a
parent800c73ff246bb57587dab930ddb73323d9584ca5 (diff)
Move common icons option to file style structview-options
All four of the view mode command-line argument parsers tested for the --icons option. Because it was common, the behaviour has been moved to the struct that handles file styles, meaning it can be parsed in one place. This is a better place for it, as the icons are to do with the file name, not the view. It also means that the lines view has no options left for it, which is fitting.
-rw-r--r--src/main.rs11
-rw-r--r--src/options/file_name.rs6
-rw-r--r--src/options/view.rs27
-rw-r--r--src/output/details.rs7
-rw-r--r--src/output/file_name.rs4
-rw-r--r--src/output/grid.rs18
-rw-r--r--src/output/grid_details.rs2
-rw-r--r--src/output/lines.rs8
-rw-r--r--src/output/mod.rs2
9 files changed, 26 insertions, 59 deletions
diff --git a/src/main.rs b/src/main.rs
index 0e2fbbb..ad1a797 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 9092b8c..283562a 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<Self, OptionsError> {
- 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 b9b38ba..bb97286 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<Self, OptionsError> {
- let lines = lines::Options { icons: matches.has(&flags::ICONS)? };
- Ok(lines)
- }
-}
-
-
impl grid::Options {
fn deduce(matches: &MatchedFlags<'_>) -> Result<Self, OptionsError> {
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 a3a33ce..10f2404 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 0165f06..70bdca8 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 f032744..79d03db 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 c52352c..c1a1203 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 5869031..5b492ca 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<File<'a>>,
pub theme: &'a Theme,
pub file_style: &'a FileStyle,
- pub opts: &'a Options,
}
impl<'a> Render<'a> {
pub fn render<W: Write>(&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 14b4f15..0361d12 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,
}