diff options
author | Dan Davison <dandavison7@gmail.com> | 2020-06-11 20:28:53 -0400 |
---|---|---|
committer | Dan Davison <dandavison7@gmail.com> | 2020-06-11 20:43:51 -0400 |
commit | 97116f284bd826cd0c2805ed3b0f4359b310ad6a (patch) | |
tree | 1905558d19979de62b6b5b45b7a2ba2825cbb2f1 /src/config.rs | |
parent | 37a6c55d11b3ffe8f9b88ac2c772f82d6b8f0efa (diff) |
New option --word-diff-regex
Fixes #184
Diffstat (limited to 'src/config.rs')
-rw-r--r-- | src/config.rs | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/src/config.rs b/src/config.rs index f8513281..d10f0dcd 100644 --- a/src/config.rs +++ b/src/config.rs @@ -4,6 +4,7 @@ use std::process; use console::Term; use git2; +use regex::Regex; use structopt::{clap, StructOpt}; use syntect::highlighting::Style as SyntectStyle; use syntect::highlighting::Theme as SyntaxTheme; @@ -68,6 +69,7 @@ pub struct Config<'a> { pub syntax_theme_name: String, pub tab_width: usize, pub true_color: bool, + pub tokenization_regex: Regex, pub zero_style: Style, } @@ -248,6 +250,16 @@ impl<'a> From<cli::Opt> for Config<'a> { .map(|s| s.parse::<f64>().unwrap_or(0.0)) .unwrap_or(0.0); + let tokenization_regex = Regex::new(&opt.tokenization_regex).unwrap_or_else(|_| { + eprintln!( + "Invalid word-diff-regex: {}. \ + The value must be a valid Rust regular expression. \ + See https://docs.rs/regex.", + opt.tokenization_regex + ); + process::exit(1); + }); + Self { background_color_extends_to_terminal_width, commit_style, @@ -291,6 +303,7 @@ impl<'a> From<cli::Opt> for Config<'a> { syntax_theme, syntax_theme_name, tab_width: opt.tab_width, + tokenization_regex, true_color, zero_style, } |