diff options
author | Balaji Sivaraman <balaji@balajisivaraman.com> | 2018-02-20 17:40:03 +0530 |
---|---|---|
committer | Andrew Gallant <jamslam@gmail.com> | 2018-02-20 07:10:03 -0500 |
commit | d57fc580818e655e7b0edca2924e259bd5dc02d2 (patch) | |
tree | 677c0ca31cc8f6cdd28ad9e56c50c516e9f0f51a /src/printer.rs | |
parent | d09538c974194865c79f9a1539cf145fd7e7430c (diff) |
termcolor: add underline support
This commit adds underline support to the termcolor crate, and
exposes it through ripgrep.
Fixes #798
Diffstat (limited to 'src/printer.rs')
-rw-r--r-- | src/printer.rs | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/src/printer.rs b/src/printer.rs index 7f0aa9b8..38b8c2b2 100644 --- a/src/printer.rs +++ b/src/printer.rs @@ -555,7 +555,8 @@ impl fmt::Display for Error { } Error::UnrecognizedStyle(ref name) => { write!(f, "Unrecognized style attribute '{}'. Choose from: \ - nobold, bold, nointense, intense.", name) + nobold, bold, nointense, intense, nounderline, \ + underline.", name) } Error::InvalidFormat(ref original) => { write!( @@ -627,7 +628,8 @@ pub struct ColorSpecs { /// Valid colors are `black`, `blue`, `green`, `red`, `cyan`, `magenta`, /// `yellow`, `white`. /// -/// Valid style instructions are `nobold`, `bold`, `intense`, `nointense`. +/// Valid style instructions are `nobold`, `bold`, `intense`, `nointense`, +/// `underline`, `nounderline`. #[derive(Clone, Debug, Eq, PartialEq)] pub struct Spec { ty: OutType, @@ -668,6 +670,8 @@ enum Style { NoBold, Intense, NoIntense, + Underline, + NoUnderline } impl ColorSpecs { @@ -727,6 +731,8 @@ impl SpecValue { Style::NoBold => { cspec.set_bold(false); } Style::Intense => { cspec.set_intense(true); } Style::NoIntense => { cspec.set_intense(false); } + Style::Underline => { cspec.set_underline(true); } + Style::NoUnderline => { cspec.set_underline(false); } } } } @@ -806,6 +812,8 @@ impl FromStr for Style { "nobold" => Ok(Style::NoBold), "intense" => Ok(Style::Intense), "nointense" => Ok(Style::NoIntense), + "underline" => Ok(Style::Underline), + "nounderline" => Ok(Style::NoUnderline), _ => Err(Error::UnrecognizedStyle(s.to_string())), } } @@ -859,6 +867,12 @@ mod tests { value: SpecValue::Style(Style::Intense), }); + let spec: Spec = "match:style:underline".parse().unwrap(); + assert_eq!(spec, Spec { + ty: OutType::Match, + value: SpecValue::Style(Style::Underline), + }); + let spec: Spec = "line:none".parse().unwrap(); assert_eq!(spec, Spec { ty: OutType::Line, |