diff options
author | Sebastian Thiel <sthiel@thoughtworks.com> | 2019-06-01 15:27:17 +0530 |
---|---|---|
committer | Sebastian Thiel <sthiel@thoughtworks.com> | 2019-06-01 15:27:44 +0530 |
commit | 9d0949933cb46d2e73c047b5f06201dbd75bca1d (patch) | |
tree | 16b9341106abc36e72a9e5e0f0f354611af51e42 /src/common.rs | |
parent | 498bcd0da4dc44d04634f2cabc245f4c46d2c46a (diff) |
Support for colors. Using green, which might be invisible to some!
Probably those who can't see red or green will have configured their
terminal to display different colors instead.
Diffstat (limited to 'src/common.rs')
-rw-r--r-- | src/common.rs | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/src/common.rs b/src/common.rs index 658a404..95b6967 100644 --- a/src/common.rs +++ b/src/common.rs @@ -1,4 +1,5 @@ use jwalk::WalkDir; +use std::fmt; use std::path::Path; pub enum ByteFormat { @@ -12,9 +13,39 @@ pub enum Sorting { Alphabetical, } +#[derive(Clone, Copy)] +pub enum Color { + None, + Terminal, +} + +pub struct DisplayColor<C> { + kind: Color, + color: C, +} + +impl Color { + pub fn display<C>(&self, color: C) -> DisplayColor<C> { + DisplayColor { kind: *self, color } + } +} + +impl<C> fmt::Display for DisplayColor<C> +where + C: fmt::Display, +{ + fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> { + match self.kind { + Color::None => Ok(()), + Color::Terminal => self.color.fmt(f), + } + } +} + pub struct WalkOptions { pub threads: usize, pub format: ByteFormat, + pub color: Color, } impl WalkOptions { |