Kaynağa Gözat

Separate classify from the other two fields

This makes the code messier, but it’s just a stepping-stone until colours gets separated too.
Benjamin Sago 8 yıl önce
ebeveyn
işleme
183ed9c135
1 değiştirilmiş dosya ile 23 ekleme ve 14 silme
  1. 23 14
      src/options/view.rs

+ 23 - 14
src/options/view.rs

@@ -19,6 +19,17 @@ pub struct View {
     pub classify: Classify,
     pub classify: Classify,
 }
 }
 
 
+impl View {
+
+    /// Determine which view to use and all of that view’s arguments.
+    pub fn deduce(matches: &getopts::Matches, filter: FileFilter, dir_action: DirAction) -> Result<View, Misfire> {
+        let (mode, colours) = Mode::deduce(matches, filter, dir_action)?;
+        let classify = Classify::deduce(matches);
+        Ok(View { mode, colours, classify })
+    }
+}
+
+
 /// The **mode** is the “type” of output.
 /// The **mode** is the “type” of output.
 #[derive(PartialEq, Debug, Clone)]
 #[derive(PartialEq, Debug, Clone)]
 pub enum Mode {
 pub enum Mode {
@@ -28,14 +39,12 @@ pub enum Mode {
     Lines,
     Lines,
 }
 }
 
 
-impl View {
+impl Mode {
 
 
-    /// Determine which view to use and all of that view’s arguments.
-    pub fn deduce(matches: &getopts::Matches, filter: FileFilter, dir_action: DirAction) -> Result<View, Misfire> {
+    /// Determine both the mode and the colours at the same time.
+    pub fn deduce(matches: &getopts::Matches, filter: FileFilter, dir_action: DirAction) -> Result<(Mode, Colours), Misfire> {
         use options::misfire::Misfire::*;
         use options::misfire::Misfire::*;
 
 
-        let classify = Classify::deduce(matches);
-
         let colour_scale = || {
         let colour_scale = || {
             matches.opt_present("color-scale") || matches.opt_present("colour-scale")
             matches.opt_present("color-scale") || matches.opt_present("colour-scale")
         };
         };
@@ -70,7 +79,7 @@ impl View {
                     xattr: xattr::ENABLED && matches.opt_present("extended"),
                     xattr: xattr::ENABLED && matches.opt_present("extended"),
                 };
                 };
 
 
-                Ok(View { mode: Mode::Details(details), colours, classify })
+                Ok((Mode::Details(details), colours))
             }
             }
         };
         };
 
 
@@ -111,7 +120,7 @@ impl View {
                         Err(Useless("across", true, "oneline"))
                         Err(Useless("across", true, "oneline"))
                     }
                     }
                     else {
                     else {
-                        Ok(View { mode: Mode::Lines, colours, classify })
+                        Ok((Mode::Lines, colours))
                     }
                     }
                 }
                 }
                 else if matches.opt_present("tree") {
                 else if matches.opt_present("tree") {
@@ -123,7 +132,7 @@ impl View {
                         xattr: false,
                         xattr: false,
                     };
                     };
 
 
-                    Ok(View { mode: Mode::Details(details), colours, classify })
+                    Ok((Mode::Details(details), colours))
                 }
                 }
                 else {
                 else {
                     let grid = Grid {
                     let grid = Grid {
@@ -131,7 +140,7 @@ impl View {
                         console_width: width,
                         console_width: width,
                     };
                     };
 
 
-                    Ok(View { mode: Mode::Grid(grid), colours, classify })
+                    Ok((Mode::Grid(grid), colours))
                 }
                 }
             }
             }
             else {
             else {
@@ -153,10 +162,10 @@ impl View {
                         xattr: false,
                         xattr: false,
                     };
                     };
 
 
-                    Ok(View { mode: Mode::Details(details), colours, classify })
+                    Ok((Mode::Details(details), colours))
                 }
                 }
                 else {
                 else {
-                    Ok(View { mode: Mode::Lines, colours, classify })
+                    Ok((Mode::Lines, colours))
                 }
                 }
             }
             }
         };
         };
@@ -164,10 +173,10 @@ impl View {
         if matches.opt_present("long") {
         if matches.opt_present("long") {
             let view = long()?;
             let view = long()?;
             if matches.opt_present("grid") {
             if matches.opt_present("grid") {
-                if let View { colours: _, classify: _, mode: Mode::Details(details) } = view {
+                if let (Mode::Details(details), _) = view {
                     let others = other_options_scan()?;
                     let others = other_options_scan()?;
-                    match others.mode {
-                        Mode::Grid(grid) => return Ok(View { mode: Mode::GridDetails(GridDetails { grid: grid, details: details }), colours: others.colours, classify: others.classify }),
+                    match others.0 {
+                        Mode::Grid(grid) => return Ok((Mode::GridDetails(GridDetails { grid, details }), others.1 )),
                         _                => return Ok(others),
                         _                => return Ok(others),
                     };
                     };
                 }
                 }