Wire up the colour-scale option

This commit is contained in:
Ben S 2016-10-30 16:42:33 +00:00
parent 86065f832d
commit 0ffb331976
4 changed files with 23 additions and 16 deletions

View File

@ -23,6 +23,7 @@ exas options are similar, but not exactly the same, as `ls`.
- **-T**, **--tree**: recurse into subdirectories in a tree view - **-T**, **--tree**: recurse into subdirectories in a tree view
- **-x**, **--across**: sort multi-column view entries across - **-x**, **--across**: sort multi-column view entries across
- **--color**, **--colour**: when to colourise the output - **--color**, **--colour**: when to colourise the output
- **--color-scale**, **--colour-scale**: colour file sizes according to their magnitude
### Filtering Options ### Filtering Options

View File

@ -7,7 +7,9 @@ DISPLAY OPTIONS
-R, --recurse recurse into directories -R, --recurse recurse into directories
-T, --tree recurse into subdirectories in a tree view -T, --tree recurse into subdirectories in a tree view
-x, --across sort multi-column view entries across -x, --across sort multi-column view entries across
--color, --colour when to colourise the output
--color=WHEN, --colour=WHEN when to colourise the output (always, auto, never)
--color-scale, --colour-scale colour file sizes according to their magnitude
FILTERING AND SORTING OPTIONS FILTERING AND SORTING OPTIONS
-a, --all show dot-files -a, --all show dot-files

View File

@ -49,14 +49,16 @@ impl Options {
opts.optflag("?", "help", "show list of command-line options"); opts.optflag("?", "help", "show list of command-line options");
// Display options // Display options
opts.optflag("1", "oneline", "display one entry per line"); opts.optflag("1", "oneline", "display one entry per line");
opts.optflag("G", "grid", "display entries in a grid view (default)"); opts.optflag("G", "grid", "display entries in a grid view (default)");
opts.optflag("l", "long", "display extended details and attributes"); opts.optflag("l", "long", "display extended details and attributes");
opts.optflag("R", "recurse", "recurse into directories"); opts.optflag("R", "recurse", "recurse into directories");
opts.optflag("T", "tree", "recurse into subdirectories in a tree view"); opts.optflag("T", "tree", "recurse into subdirectories in a tree view");
opts.optflag("x", "across", "sort multi-column view entries across"); opts.optflag("x", "across", "sort multi-column view entries across");
opts.optopt ("", "color", "when to show anything in colours", "WHEN"); opts.optopt ("", "color", "when to show anything in colours", "WHEN");
opts.optopt ("", "colour", "when to show anything in colours (alternate spelling)", "WHEN"); opts.optopt ("", "colour", "when to show anything in colours (alternate spelling)", "WHEN");
opts.optflag("", "color-scale", "use a colour scale when displaying file sizes (alternate spelling)");
opts.optflag("", "colour-scale", "use a colour scale when displaying file sizes");
// Filtering and sorting options // Filtering and sorting options
opts.optflag("", "group-directories-first", "list directories before other files"); opts.optflag("", "group-directories-first", "list directories before other files");

View File

@ -25,6 +25,10 @@ impl View {
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<View, Misfire> {
use options::misfire::Misfire::*; use options::misfire::Misfire::*;
let colour_scale = || {
matches.opt_present("color-scale") || matches.opt_present("colour-scale")
};
let long = || { let long = || {
if matches.opt_present("across") && !matches.opt_present("grid") { if matches.opt_present("across") && !matches.opt_present("grid") {
Err(Useless("across", true, "long")) Err(Useless("across", true, "long"))
@ -34,13 +38,12 @@ impl View {
} }
else { else {
let term_colours = try!(TerminalColours::deduce(matches)); let term_colours = try!(TerminalColours::deduce(matches));
let scale = true;
let colours = match term_colours { let colours = match term_colours {
TerminalColours::Always => Colours::colourful(scale), TerminalColours::Always => Colours::colourful(colour_scale()),
TerminalColours::Never => Colours::plain(), TerminalColours::Never => Colours::plain(),
TerminalColours::Automatic => { TerminalColours::Automatic => {
if dimensions().is_some() { if dimensions().is_some() {
Colours::colourful(scale) Colours::colourful(colour_scale())
} }
else { else {
Colours::plain() Colours::plain()
@ -85,13 +88,12 @@ impl View {
let other_options_scan = || { let other_options_scan = || {
let term_colours = try!(TerminalColours::deduce(matches)); let term_colours = try!(TerminalColours::deduce(matches));
let term_width = try!(TerminalWidth::deduce()); let term_width = try!(TerminalWidth::deduce());
let scale = true;
if let Some(&width) = term_width.as_ref() { if let Some(&width) = term_width.as_ref() {
let colours = match term_colours { let colours = match term_colours {
TerminalColours::Always => Colours::colourful(scale), TerminalColours::Always => Colours::colourful(colour_scale()),
TerminalColours::Never => Colours::plain(), TerminalColours::Never => Colours::plain(),
TerminalColours::Automatic => Colours::colourful(scale), TerminalColours::Automatic => Colours::colourful(colour_scale()),
}; };
if matches.opt_present("oneline") { if matches.opt_present("oneline") {
@ -134,7 +136,7 @@ impl View {
// fallback to the lines view. // fallback to the lines view.
let colours = match term_colours { let colours = match term_colours {
TerminalColours::Always => Colours::colourful(scale), TerminalColours::Always => Colours::colourful(colour_scale()),
TerminalColours::Never => Colours::plain(), TerminalColours::Never => Colours::plain(),
TerminalColours::Automatic => Colours::plain(), TerminalColours::Automatic => Colours::plain(),
}; };