From b86074d63b183eda8f5cd26d339864bac4328084 Mon Sep 17 00:00:00 2001 From: Benjamin Sago Date: Wed, 13 Sep 2017 08:44:59 +0100 Subject: [PATCH] Rename Style to Styles to avoid a name clash --- src/options/style.rs | 20 +++++++++++++++----- src/options/view.rs | 4 ++-- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/src/options/style.rs b/src/options/style.rs index 2aede039..061fef23 100644 --- a/src/options/style.rs +++ b/src/options/style.rs @@ -60,12 +60,22 @@ impl TerminalColours { } -pub struct Style { +/// **Styles**, which is already an overloaded term, is a pair of view option +/// sets that happen to both be affected by `LS_COLORS` and `EXA_COLORS`. +/// Because it’s better to only iterate through that once, the two are deduced +/// together. +pub struct Styles { + + /// The colours to paint user interface elements, like the date column, + /// and file kinds, such as directories. pub colours: Colours, + + /// The colours to paint the names of files that match glob patterns + /// (and the classify option). pub style: FileStyle, } -impl Style { +impl Styles { #[allow(trivial_casts)] // the "as Box<_>" stuff below warns about this for some reason pub fn deduce(matches: &MatchedFlags, vars: &V, widther: TW) -> Result @@ -80,7 +90,7 @@ impl Style { let tc = TerminalColours::deduce(matches)?; if tc == Never || (tc == Automatic && widther().is_none()) { - return Ok(Style { + return Ok(Styles { colours: Colours::plain(), style: FileStyle { classify, exts: Box::new(NoFileColours) }, }); @@ -101,14 +111,14 @@ impl Style { LSColors(exa.as_ref()).each_pair(|pair| { colours.set_exa(&pair); }); + let style = FileStyle { classify, exts }; + Ok(Styles { colours, style }) } let classify = Classify::deduce(matches)?; let exts = if colours.colourful { Box::new(FileExtensions) as Box<_> } else { Box::new(NoFileColours) as Box<_> }; - let style = FileStyle { classify, exts }; - Ok(Style { colours, style }) } } diff --git a/src/options/view.rs b/src/options/view.rs index 8d4520d8..deff1143 100644 --- a/src/options/view.rs +++ b/src/options/view.rs @@ -13,10 +13,10 @@ impl View { /// Determine which view to use and all of that view’s arguments. pub fn deduce(matches: &MatchedFlags, vars: &V) -> Result { - use options::style::Style; + use options::style::Styles; let mode = Mode::deduce(matches, vars)?; - let Style { colours, style } = Style::deduce(matches, vars, || *TERM_WIDTH)?; + let Styles { colours, style } = Styles::deduce(matches, vars, || *TERM_WIDTH)?; Ok(View { mode, colours, style }) } }