提交 183ed9c1 编写于 作者: B Benjamin Sago

Separate classify from the other two fields

This makes the code messier, but it’s just a stepping-stone until colours gets separated too.
上级 4e90b4d7
...@@ -19,6 +19,17 @@ pub struct View { ...@@ -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 { ...@@ -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. /// Determine both the mode and the colours at the same time.
pub fn deduce(matches: &getopts::Matches, filter: FileFilter, dir_action: DirAction) -> Result<View, Misfire> { 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 { ...@@ -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 { ...@@ -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 { ...@@ -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 { ...@@ -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 { ...@@ -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 { ...@@ -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 { match others.0 {
Mode::Grid(grid) => return Ok(View { mode: Mode::GridDetails(GridDetails { grid: grid, details: details }), colours: others.colours, classify: others.classify }), Mode::Grid(grid) => return Ok((Mode::GridDetails(GridDetails { grid, details }), others.1 )),
_ => return Ok(others), _ => return Ok(others),
}; };
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册