summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorAndrew Gallant <jamslam@gmail.com>2017-01-06 20:07:29 -0500
committerAndrew Gallant <jamslam@gmail.com>2017-01-06 20:09:51 -0500
commitb187c1a8175d88b743e2e225dbec98661f7a2f94 (patch)
treebfb55fdc1e8704fd2a63d6ce922e527b62921faa /src
parentf7a2fe30d4f0fe055e63a630c940383a1d63d6a9 (diff)
Rejigger bold and intense settings.
Previously, ripgrep would only emit the 'bold' ANSI escape sequence if no foreground or background color was set. Instead, it would convert colors to their "intense" versions if bold was set. The intent was to do the same thing on Windows and Unix. However, this had a few negative side effects: 1. Omitting the 'bold' ANSI escape when 'bold' was set is surprising. 2. Intense colors can look quite bad and be hard to read. To fix this, we introduce a new setting called 'intense' in the --colors flag, and thread that down through to the public API of the `termcolor` crate. The 'intense' setting has environment specific behavior: 1. In ANSI mode, it will convert the selected color to its "intense" variant. 2. In the Windows console, it will make the text "intense." There is no longer any "smart" handling of the 'bold' style. The 'bold' ANSI escape is always emitted when it is selected. In the Windows console, the 'bold' setting now has no effect. Note that this is a breaking change. Fixes #266, #293
Diffstat (limited to 'src')
-rw-r--r--src/app.rs16
-rw-r--r--src/args.rs7
-rw-r--r--src/printer.rs12
3 files changed, 23 insertions, 12 deletions
diff --git a/src/app.rs b/src/app.rs
index 13b1ac60..8466b2ba 100644
--- a/src/app.rs
+++ b/src/app.rs
@@ -237,14 +237,14 @@ lazy_static! {
This flag may be provided multiple times. Settings are applied \
iteratively. Colors are limited to one of eight choices: \
red, blue, green, cyan, magenta, yellow, white and black. \
- Styles are limited to either nobold or bold.\n\nThe format \
- of the flag is {type}:{attribute}:{value}. {type} should be \
- one of path, line or match. {attribute} can be fg, bg or style. \
- {value} is either a color (for fg and bg) or a text style. \
- A special format, {type}:none, will clear all color settings \
- for {type}.\n\nFor example, the following command will change \
- the match color to magenta and the background color for line \
- numbers to yellow:\n\n\
+ Styles are limited to nobold, bold, nointense or intense.\n\n
+ The format of the flag is {type}:{attribute}:{value}. {type} \
+ should be one of path, line or match. {attribute} can be fg, bg \
+ or style. {value} is either a color (for fg and bg) or a text \
+ style. A special format, {type}:none, will clear all color \
+ settings for {type}.\n\nFor example, the following command will \
+ change the match color to magenta and the background color for \
+ line numbers to yellow:\n\n\
rg --colors 'match:fg:magenta' --colors 'line:bg:yellow' foo.");
doc!(h, "fixed-strings",
"Treat the pattern as a literal string.",
diff --git a/src/args.rs b/src/args.rs
index 9ce572ac..18da6f66 100644
--- a/src/args.rs
+++ b/src/args.rs
@@ -640,11 +640,10 @@ impl<'a> ArgMatches<'a> {
fn color_specs(&self) -> Result<ColorSpecs> {
// Start with a default set of color specs.
let mut specs = vec![
- "path:fg:green".parse().unwrap(),
- "path:style:bold".parse().unwrap(),
- "line:fg:blue".parse().unwrap(),
- "line:style:bold".parse().unwrap(),
+ "path:fg:magenta".parse().unwrap(),
+ "line:fg:green".parse().unwrap(),
"match:fg:red".parse().unwrap(),
+ "match:style:intense".parse().unwrap(),
"match:style:bold".parse().unwrap(),
];
for spec_str in self.values_of_lossy_vec("colors") {
diff --git a/src/printer.rs b/src/printer.rs
index 96b0444b..c57e1611 100644
--- a/src/printer.rs
+++ b/src/printer.rs
@@ -523,6 +523,8 @@ enum SpecType {
enum Style {
Bold,
NoBold,
+ Intense,
+ NoIntense,
}
impl ColorSpecs {
@@ -574,6 +576,8 @@ impl SpecValue {
match *style {
Style::Bold => { cspec.set_bold(true); }
Style::NoBold => { cspec.set_bold(false); }
+ Style::Intense => { cspec.set_intense(true); }
+ Style::NoIntense => { cspec.set_intense(false); }
}
}
}
@@ -650,6 +654,8 @@ impl FromStr for Style {
match &*s.to_lowercase() {
"bold" => Ok(Style::Bold),
"nobold" => Ok(Style::NoBold),
+ "intense" => Ok(Style::Intense),
+ "nointense" => Ok(Style::NoIntense),
_ => Err(Error::UnrecognizedStyle(s.to_string())),
}
}
@@ -696,6 +702,12 @@ mod tests {
value: SpecValue::Style(Style::Bold),
});
+ let spec: Spec = "match:style:intense".parse().unwrap();
+ assert_eq!(spec, Spec {
+ ty: OutType::Match,
+ value: SpecValue::Style(Style::Intense),
+ });
+
let spec: Spec = "line:none".parse().unwrap();
assert_eq!(spec, Spec {
ty: OutType::Line,