diff options
author | Ben S <ogham@bsago.me> | 2015-05-09 23:57:18 +0100 |
---|---|---|
committer | Ben S <ogham@bsago.me> | 2015-05-09 23:57:18 +0100 |
commit | 36116a142095d61ab7f601cb6efda03d2cb8d749 (patch) | |
tree | 8b4057bc23c5a92565610d9067077c87a6e1211b /src/options.rs | |
parent | da49b80c3525db7f0a0aae0fe2ac3e0a9a574cd3 (diff) |
Add colours module, and disable them sometimes
Colours are now disabled when output is not to a terminal. Fixes #53!
This required some internal restructuring - colours are now in their own object that gets passed around everywhere it's needed.
Diffstat (limited to 'src/options.rs')
-rw-r--r-- | src/options.rs | 47 |
1 files changed, 30 insertions, 17 deletions
diff --git a/src/options.rs b/src/options.rs index 8143e71..bff0d12 100644 --- a/src/options.rs +++ b/src/options.rs @@ -1,9 +1,10 @@ +use colours::Colours; use dir::Dir; use file::File; use column::Column; use column::Column::*; use feature::Attribute; -use output::{Grid, Details}; +use output::{Grid, Details, Lines}; use term::dimensions; use std::cmp::Ordering; @@ -38,7 +39,7 @@ pub struct FileFilter { #[derive(PartialEq, Debug, Copy, Clone)] pub enum View { Details(Details), - Lines, + Lines(Lines), Grid(Grid), } @@ -257,6 +258,7 @@ impl View { header: matches.opt_present("header"), recurse: dir_action.recurse_options().map(|o| (o, filter)), xattr: Attribute::feature_implemented() && matches.opt_present("extended"), + colours: if dimensions().is_some() { Colours::colourful() } else { Colours::plain() }, }; Ok(View::Details(details)) @@ -298,33 +300,44 @@ impl View { else if Attribute::feature_implemented() && matches.opt_present("extended") { Err(Misfire::Useless("extended", false, "long")) } - else if matches.opt_present("oneline") { - if matches.opt_present("across") { - Err(Misfire::Useless("across", true, "oneline")) + else if let Some((width, _)) = dimensions() { + if matches.opt_present("oneline") { + if matches.opt_present("across") { + Err(Misfire::Useless("across", true, "oneline")) + } + else { + let lines = Lines { + colours: Colours::colourful(), + }; + + Ok(View::Lines(lines)) + } } else { - Ok(View::Lines) - } - } - else { - if let Some((width, _)) = dimensions() { let grid = Grid { across: matches.opt_present("across"), - console_width: width + console_width: width, + colours: Colours::colourful(), }; Ok(View::Grid(grid)) } - else { - // If the terminal width couldn't be matched for some reason, such - // as the program's stdout being connected to a file, then - // fallback to the lines view. - Ok(View::Lines) - } + } + else { + // If the terminal width couldn't be matched for some reason, such + // as the program's stdout being connected to a file, then + // fallback to the lines view. + let lines = Lines { + colours: Colours::plain(), + }; + + Ok(View::Lines(lines)) } } } + + #[derive(PartialEq, Debug, Copy, Clone)] pub enum SizeFormat { DecimalBytes, |