Merge pull request #64 from jaemk/configurable_debounce

Add `-d, --debounce` option
This commit is contained in:
Matt Green 2017-09-08 16:16:19 -04:00 committed by GitHub
commit 06fd2954dd
2 changed files with 21 additions and 7 deletions

View File

@ -12,6 +12,7 @@ pub struct Args {
pub clear_screen: bool,
pub signal: Option<String>,
pub restart: bool,
pub debounce: u64,
pub debug: bool,
pub run_initially: bool,
pub no_shell: bool,
@ -72,10 +73,16 @@ pub fn get_args() -> Args {
.help("Send SIGKILL to child processes (deprecated, use -s SIGKILL instead)")
.short("k")
.long("kill"))
.arg(Arg::with_name("debug")
.help("Print debugging messages to stderr")
.arg(Arg::with_name("debounce")
.help("Set the timeout between detected change and command execution, defaults to 500ms")
.takes_value(true)
.value_name("milliseconds")
.short("d")
.long("debug"))
.long("debounce"))
.arg(Arg::with_name("verbose")
.help("Print debugging messages to stderr")
.short("v")
.long("verbose"))
.arg(Arg::with_name("filter")
.help("Ignore all modifications except those matching the pattern")
.short("f")
@ -157,6 +164,12 @@ pub fn get_args() -> Args {
1000
};
let debounce = if args.occurrences_of("debounce") > 0 {
value_t!(args.value_of("debounce"), u64).unwrap_or_else(|e| e.exit())
} else {
500
};
if signal.is_some() && args.is_present("postpone") {
// TODO: Error::argument_conflict() might be the better fit, usage was unclear, though
Error::value_validation_auto("--postpone and --signal are mutually exclusive".to_string())
@ -177,7 +190,8 @@ pub fn get_args() -> Args {
signal: signal,
clear_screen: args.is_present("clear"),
restart: args.is_present("restart"),
debug: args.is_present("debug"),
debounce: debounce,
debug: args.is_present("verbose"),
run_initially: !args.is_present("postpone"),
no_shell: args.is_present("no-shell"),
no_vcs_ignore: args.is_present("no-vcs-ignore"),

View File

@ -87,7 +87,7 @@ pub fn run(args: cli::Args) {
loop {
debug!("Waiting for filesystem activity");
let paths = wait_fs(&rx, &filter);
let paths = wait_fs(&rx, &filter, args.debounce);
if let Some(path) = paths.get(0) {
debug!("Path updated: {:?}", path);
}
@ -167,7 +167,7 @@ pub fn run(args: cli::Args) {
}
}
fn wait_fs(rx: &Receiver<Event>, filter: &NotificationFilter) -> Vec<PathBuf> {
fn wait_fs(rx: &Receiver<Event>, filter: &NotificationFilter, debounce: u64) -> Vec<PathBuf> {
let mut paths = vec![];
let mut cache = HashMap::new();
@ -190,7 +190,7 @@ fn wait_fs(rx: &Receiver<Event>, filter: &NotificationFilter) -> Vec<PathBuf> {
}
// Wait for filesystem activity to cool off
let timeout = Duration::from_millis(500);
let timeout = Duration::from_millis(debounce);
while let Ok(e) = rx.recv_timeout(timeout) {
if let Some(ref path) = e.path {
if cache.contains_key(path) {