--disable option to turn bultin matchers off

This commit is contained in:
FliegendeWurst 2021-04-20 09:26:50 +02:00
parent 79ee5abc7c
commit 10a2d4bba1
3 changed files with 28 additions and 1 deletions

View File

@ -103,6 +103,13 @@ fn app_args<'a>() -> clap::ArgMatches<'a> {
.default_value("left")
.short("p"),
)
.arg(
Arg::with_name("disable")
.help("Disable a default pattern")
.long("disable")
.takes_value(true)
.multiple(true)
)
.arg(
Arg::with_name("regexp")
.help("Use this regexp as extra pattern to match")
@ -142,6 +149,8 @@ fn main() {
} else {
[].to_vec()
};
let disable = args.values_of("disable")
.map(|x| x.collect::<Vec<_>>()).unwrap_or_default();
let foreground_color = colors::get_color(args.value_of("foreground_color").unwrap());
let background_color = colors::get_color(args.value_of("background_color").unwrap());
@ -165,7 +174,7 @@ fn main() {
}
).collect();
let mut state = state::State::new(&lines, &unescaped, alphabet, &regexp);
let mut state = state::State::new_with_exclude(&lines, &unescaped, alphabet, &regexp, &disable);
let selected = {
let mut viewbox = view::View::new(

View File

@ -55,6 +55,7 @@ pub struct State<'a> {
pub unescaped: &'a Vec<String>,
alphabet: &'a str,
regexp: &'a Vec<&'a str>,
exclude_default: &'a [&'a str]
}
impl<'a> State<'a> {
@ -64,6 +65,17 @@ impl<'a> State<'a> {
unescaped,
alphabet,
regexp,
exclude_default: &[]
}
}
pub fn new_with_exclude(lines: &'a Vec<&'a str>, unescaped: &'a Vec<String>, alphabet: &'a str, regexp: &'a Vec<&'a str>, exclude_default: &'a [&'a str]) -> State<'a> {
State {
lines,
unescaped,
alphabet,
regexp,
exclude_default,
}
}
@ -72,6 +84,7 @@ impl<'a> State<'a> {
let exclude_patterns = EXCLUDE_PATTERNS
.iter()
.filter(|(name, _)| !self.exclude_default.contains(name))
.map(|tuple| (tuple.0, Regex::new(tuple.1).unwrap()))
.collect::<Vec<_>>();
@ -83,6 +96,7 @@ impl<'a> State<'a> {
let patterns = PATTERNS
.iter()
.filter(|(name, _)| !self.exclude_default.contains(name))
.map(|tuple| (tuple.0, Regex::new(tuple.1).unwrap()))
.collect::<Vec<_>>();

View File

@ -186,6 +186,10 @@ impl<'a> Swapper<'a> {
return vec!["--regexp".to_string(), format!("'{}'", value.replace("\\\\", "\\"))];
}
if name.starts_with("disable") {
return vec!["--disable".to_owned(), value.to_owned()];
}
vec![]
} else {
vec![]