diff --git a/src/options/view.rs b/src/options/view.rs index ed22111..c64fac4 100644 --- a/src/options/view.rs +++ b/src/options/view.rs @@ -34,12 +34,13 @@ impl View { } else { let term_colours = try!(TerminalColours::deduce(matches)); + let scale = true; let colours = match term_colours { - TerminalColours::Always => Colours::colourful(), + TerminalColours::Always => Colours::colourful(scale), TerminalColours::Never => Colours::plain(), TerminalColours::Automatic => { if dimensions().is_some() { - Colours::colourful() + Colours::colourful(scale) } else { Colours::plain() @@ -84,12 +85,13 @@ impl View { let other_options_scan = || { let term_colours = try!(TerminalColours::deduce(matches)); let term_width = try!(TerminalWidth::deduce()); + let scale = true; if let Some(&width) = term_width.as_ref() { let colours = match term_colours { - TerminalColours::Always => Colours::colourful(), + TerminalColours::Always => Colours::colourful(scale), TerminalColours::Never => Colours::plain(), - TerminalColours::Automatic => Colours::colourful(), + TerminalColours::Automatic => Colours::colourful(scale), }; if matches.opt_present("oneline") { @@ -132,7 +134,7 @@ impl View { // fallback to the lines view. let colours = match term_colours { - TerminalColours::Always => Colours::colourful(), + TerminalColours::Always => Colours::colourful(scale), TerminalColours::Never => Colours::plain(), TerminalColours::Automatic => Colours::plain(), }; diff --git a/src/output/colours.rs b/src/output/colours.rs index 257e40e..d9510ac 100644 --- a/src/output/colours.rs +++ b/src/output/colours.rs @@ -4,6 +4,8 @@ use ansi_term::Colour::{Red, Green, Yellow, Blue, Cyan, Purple, Fixed}; #[derive(Clone, Copy, Debug, Default, PartialEq)] pub struct Colours { + pub scale: bool, + pub filetypes: FileTypes, pub perms: Permissions, pub size: Size, @@ -96,8 +98,10 @@ impl Colours { Colours::default() } - pub fn colourful() -> Colours { + pub fn colourful(scale: bool) -> Colours { Colours { + scale: scale, + filetypes: FileTypes { normal: Style::default(), directory: Blue.bold(), @@ -170,7 +174,26 @@ impl Colours { } } - pub fn file_size(&self, _size: u64) -> Style { - self.size.numbers + pub fn file_size(&self, size: u64) -> Style { + if self.scale { + if size < 1024 { + Fixed(118).normal() + } + else if size < 1024 * 1024 { + Fixed(190).normal() + } + else if size < 1024 * 1024 * 1024 { + Fixed(226).normal() + } + else if size < 1024 * 1024 * 1024 * 1024 { + Fixed(220).normal() + } + else { + Fixed(214).normal() + } + } + else { + self.size.numbers + } } }