summaryrefslogtreecommitdiffstats
path: root/src/config.rs
diff options
context:
space:
mode:
authorDan Davison <dandavison7@gmail.com>2020-05-25 07:03:08 -0400
committerDan Davison <dandavison7@gmail.com>2020-05-26 09:21:49 -0400
commit9acd37160f97f6de8d1ea018619a6eb84accbfd2 (patch)
tree795950df6741ec6a0d513fee3ffb44dc3d6c7529 /src/config.rs
parent53f0de7b1ef168adb2a86f06b2682bacb79ff6b6 (diff)
Rewrite {commit, file, hunk} {style, decoration-style} strings
Diffstat (limited to 'src/config.rs')
-rw-r--r--src/config.rs36
1 files changed, 10 insertions, 26 deletions
diff --git a/src/config.rs b/src/config.rs
index 27369cea..e815de16 100644
--- a/src/config.rs
+++ b/src/config.rs
@@ -9,7 +9,7 @@ use syntect::parsing::SyntaxSet;
use crate::bat::output::PagingMode;
use crate::bat::terminal::to_ansi_color;
-use crate::cli::{self, unreachable};
+use crate::cli::{self, extract_special_attribute, unreachable};
use crate::env;
use crate::style::{self, DecorationStyle, Style};
use crate::syntect_color;
@@ -309,8 +309,8 @@ pub fn parse_style(
true_color,
);
let decoration_style = match decoration_style_string {
- Some(s) => parse_decoration_style_string(s, true_color),
- None => None,
+ Some(s) if s != "" => parse_decoration_style_string(s, true_color),
+ _ => None,
};
Style {
ansi_term_style,
@@ -378,37 +378,21 @@ fn parse_ansi_term_style(
fn parse_decoration_style_string(style_string: &str, true_color: bool) -> Option<DecorationStyle> {
let style_string = style_string.to_lowercase();
- let (special_attributes, standard_attributes): (Vec<&str>, Vec<&str>) =
- style_string.split_whitespace().partition(|&token| {
- token == "box" || token == "underline" || token == "omit" || token == "plain"
- });
- if special_attributes.len() > 1 {
+ let (style_string, special_attribute) = extract_special_attribute(&style_string);
+ let special_attribute = special_attribute.unwrap_or_else(|| {
eprintln!(
- "Encountered multiple special attributes: {:?}. \
- You may supply no more than one of the special attributes 'box', 'underline', and 'omit'.",
- special_attributes.join(", ")
+ "To specify a decoration style, you must supply one of the special attributes \
+ 'box', 'underline', or 'omit'.",
);
- std::process::exit(1);
- } else if special_attributes.len() == 0 {
- if standard_attributes.len() > 0 {
- eprintln!(
- "To specify a decoration style, you must supply one of the special attributes \
- 'box', 'underline', or 'omit'.",
- );
- std::process::exit(1);
- } else {
- return None;
- }
- };
- let special_attribute = special_attributes[0];
- let style_string = standard_attributes.join(" ");
+ process::exit(1);
+ });
let (style, is_syntax_highlighted): (ansi_term::Style, bool) =
parse_ansi_term_style(&style_string, None, None, true_color);
if is_syntax_highlighted {
eprintln!("'syntax' may not be used as a color name in a decoration style.");
process::exit(1);
};
- match special_attribute {
+ match special_attribute.as_ref() {
"box" => Some(DecorationStyle::Box(style)),
"underline" => Some(DecorationStyle::Underline(style)),
"omit" => Some(DecorationStyle::Omit),