mirror of
https://github.com/FliegendeWurst/tmux-thumbs.git
synced 2024-11-24 22:04:57 +00:00
--disable option to turn bultin matchers off
This commit is contained in:
parent
79ee5abc7c
commit
10a2d4bba1
11
src/main.rs
11
src/main.rs
@ -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, ®exp);
|
||||
let mut state = state::State::new_with_exclude(&lines, &unescaped, alphabet, ®exp, &disable);
|
||||
|
||||
let selected = {
|
||||
let mut viewbox = view::View::new(
|
||||
|
14
src/state.rs
14
src/state.rs
@ -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<_>>();
|
||||
|
||||
|
@ -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![]
|
||||
|
Loading…
Reference in New Issue
Block a user