mirror of
https://github.com/FliegendeWurst/tmux-thumbs.git
synced 2024-11-09 16:00:35 +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")
|
.default_value("left")
|
||||||
.short("p"),
|
.short("p"),
|
||||||
)
|
)
|
||||||
|
.arg(
|
||||||
|
Arg::with_name("disable")
|
||||||
|
.help("Disable a default pattern")
|
||||||
|
.long("disable")
|
||||||
|
.takes_value(true)
|
||||||
|
.multiple(true)
|
||||||
|
)
|
||||||
.arg(
|
.arg(
|
||||||
Arg::with_name("regexp")
|
Arg::with_name("regexp")
|
||||||
.help("Use this regexp as extra pattern to match")
|
.help("Use this regexp as extra pattern to match")
|
||||||
@ -142,6 +149,8 @@ fn main() {
|
|||||||
} else {
|
} else {
|
||||||
[].to_vec()
|
[].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 foreground_color = colors::get_color(args.value_of("foreground_color").unwrap());
|
||||||
let background_color = colors::get_color(args.value_of("background_color").unwrap());
|
let background_color = colors::get_color(args.value_of("background_color").unwrap());
|
||||||
@ -165,7 +174,7 @@ fn main() {
|
|||||||
}
|
}
|
||||||
).collect();
|
).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 selected = {
|
||||||
let mut viewbox = view::View::new(
|
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>,
|
pub unescaped: &'a Vec<String>,
|
||||||
alphabet: &'a str,
|
alphabet: &'a str,
|
||||||
regexp: &'a Vec<&'a str>,
|
regexp: &'a Vec<&'a str>,
|
||||||
|
exclude_default: &'a [&'a str]
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> State<'a> {
|
impl<'a> State<'a> {
|
||||||
@ -64,6 +65,17 @@ impl<'a> State<'a> {
|
|||||||
unescaped,
|
unescaped,
|
||||||
alphabet,
|
alphabet,
|
||||||
regexp,
|
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
|
let exclude_patterns = EXCLUDE_PATTERNS
|
||||||
.iter()
|
.iter()
|
||||||
|
.filter(|(name, _)| !self.exclude_default.contains(name))
|
||||||
.map(|tuple| (tuple.0, Regex::new(tuple.1).unwrap()))
|
.map(|tuple| (tuple.0, Regex::new(tuple.1).unwrap()))
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
|
|
||||||
@ -83,6 +96,7 @@ impl<'a> State<'a> {
|
|||||||
|
|
||||||
let patterns = PATTERNS
|
let patterns = PATTERNS
|
||||||
.iter()
|
.iter()
|
||||||
|
.filter(|(name, _)| !self.exclude_default.contains(name))
|
||||||
.map(|tuple| (tuple.0, Regex::new(tuple.1).unwrap()))
|
.map(|tuple| (tuple.0, Regex::new(tuple.1).unwrap()))
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
|
|
||||||
|
@ -186,6 +186,10 @@ impl<'a> Swapper<'a> {
|
|||||||
return vec!["--regexp".to_string(), format!("'{}'", value.replace("\\\\", "\\"))];
|
return vec!["--regexp".to_string(), format!("'{}'", value.replace("\\\\", "\\"))];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if name.starts_with("disable") {
|
||||||
|
return vec!["--disable".to_owned(), value.to_owned()];
|
||||||
|
}
|
||||||
|
|
||||||
vec![]
|
vec![]
|
||||||
} else {
|
} else {
|
||||||
vec![]
|
vec![]
|
||||||
|
Loading…
Reference in New Issue
Block a user