From d57fc580818e655e7b0edca2924e259bd5dc02d2 Mon Sep 17 00:00:00 2001 From: Balaji Sivaraman Date: Tue, 20 Feb 2018 17:40:03 +0530 Subject: termcolor: add underline support This commit adds underline support to the termcolor crate, and exposes it through ripgrep. Fixes #798 --- termcolor/src/lib.rs | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) (limited to 'termcolor') diff --git a/termcolor/src/lib.rs b/termcolor/src/lib.rs index 13b9fe24..f1c36cbe 100644 --- a/termcolor/src/lib.rs +++ b/termcolor/src/lib.rs @@ -980,6 +980,9 @@ impl WriteColor for Ansi { if spec.bold { self.write_str("\x1B[1m")?; } + if spec.underline { + self.write_str("\x1B[4m")?; + } Ok(()) } @@ -1212,6 +1215,7 @@ pub struct ColorSpec { bg_color: Option, bold: bool, intense: bool, + underline: bool, } impl ColorSpec { @@ -1251,6 +1255,19 @@ impl ColorSpec { self } + /// Get whether this is underline or not. + /// + /// Note that the underline setting has no effect in a Windows console. + pub fn underline(&self) -> bool { self.underline } + + /// Set whether the text is underlined or not. + /// + /// Note that the underline setting has no effect in a Windows console. + pub fn set_underline(&mut self, yes: bool) -> &mut ColorSpec { + self.underline = yes; + self + } + /// Get whether this is intense or not. pub fn intense(&self) -> bool { self.intense } @@ -1262,7 +1279,8 @@ impl ColorSpec { /// Returns true if this color specification has no colors or styles. pub fn is_none(&self) -> bool { - self.fg_color.is_none() && self.bg_color.is_none() && !self.bold + self.fg_color.is_none() && self.bg_color.is_none() + && !self.bold && !self.underline } /// Clears this color specification so that it has no color/style settings. @@ -1270,6 +1288,7 @@ impl ColorSpec { self.fg_color = None; self.bg_color = None; self.bold = false; + self.underline = false; } /// Writes this color spec to the given Windows console. -- cgit v1.2.3