diff options
author | Aram Drevekenin <aram@poor.dev> | 2023-06-15 17:54:21 +0200 |
---|---|---|
committer | Aram Drevekenin <aram@poor.dev> | 2023-06-15 17:54:21 +0200 |
commit | 4adb22d22eb38228815c32465bf4f3a9017c938e (patch) | |
tree | 49f7cbe92eb88f4111956546463fc9a7783d3adf | |
parent | 76f50ea12350a9dec6246bc9b310a46df92fe4b1 (diff) |
style(fmt): rustfmt
-rw-r--r-- | zellij-server/src/plugins/watch_filesystem.rs | 115 | ||||
-rw-r--r-- | zellij-utils/src/lib.rs | 4 |
2 files changed, 70 insertions, 49 deletions
diff --git a/zellij-server/src/plugins/watch_filesystem.rs b/zellij-server/src/plugins/watch_filesystem.rs index 998649e5d..8ab451991 100644 --- a/zellij-server/src/plugins/watch_filesystem.rs +++ b/zellij-server/src/plugins/watch_filesystem.rs @@ -2,18 +2,27 @@ use super::PluginInstruction; use std::path::PathBuf; use crate::thread_bus::ThreadSenders; -use std::time::Duration; use std::path::Path; +use std::time::Duration; +use zellij_utils::notify_debouncer_full::{ + new_debouncer, + notify::{EventKind, INotifyWatcher, RecursiveMode, Watcher}, + DebounceEventResult, Debouncer, FileIdMap, +}; use zellij_utils::{data::Event, errors::prelude::Result}; -use zellij_utils::notify_debouncer_full::{notify::{Watcher, INotifyWatcher, EventKind, RecursiveMode}, new_debouncer, DebounceEventResult, Debouncer, FileIdMap}; const DEBOUNCE_DURATION_MS: u64 = 500; -pub fn watch_filesystem(senders: ThreadSenders, zellij_cwd: &Path) -> Result<Debouncer<INotifyWatcher, FileIdMap>> { +pub fn watch_filesystem( + senders: ThreadSenders, + zellij_cwd: &Path, +) -> Result<Debouncer<INotifyWatcher, FileIdMap>> { let path_prefix_in_plugins = PathBuf::from("/host"); let current_dir = PathBuf::from(zellij_cwd); - let mut debouncer = new_debouncer(Duration::from_millis(DEBOUNCE_DURATION_MS), None, + let mut debouncer = new_debouncer( + Duration::from_millis(DEBOUNCE_DURATION_MS), + None, move |result: DebounceEventResult| match result { Ok(events) => { let mut create_events = vec![]; @@ -29,50 +38,58 @@ pub fn watch_filesystem(senders: ThreadSenders, zellij_cwd: &Path) -> Result<Deb _ => {}, } } - let create_paths: Vec<PathBuf> = create_events.drain(..).map(|e| { - e - .paths - .iter() - .map(|p| { - let stripped_prefix_path = - p.strip_prefix(¤t_dir).unwrap_or_else(|_| p); - path_prefix_in_plugins.join(stripped_prefix_path) + let create_paths: Vec<PathBuf> = create_events + .drain(..) + .map(|e| { + e.paths + .iter() + .map(|p| { + let stripped_prefix_path = + p.strip_prefix(¤t_dir).unwrap_or_else(|_| p); + path_prefix_in_plugins.join(stripped_prefix_path) + }) + .collect() }) - .collect() - }).collect(); - let read_paths: Vec<PathBuf> = read_events.drain(..).map(|e| { - e - .paths - .iter() - .map(|p| { - let stripped_prefix_path = - p.strip_prefix(¤t_dir).unwrap_or_else(|_| p); - path_prefix_in_plugins.join(stripped_prefix_path) + .collect(); + let read_paths: Vec<PathBuf> = read_events + .drain(..) + .map(|e| { + e.paths + .iter() + .map(|p| { + let stripped_prefix_path = + p.strip_prefix(¤t_dir).unwrap_or_else(|_| p); + path_prefix_in_plugins.join(stripped_prefix_path) + }) + .collect() }) - .collect() - }).collect(); - let update_paths: Vec<PathBuf> = update_events.drain(..).map(|e| { - e - .paths - .iter() - .map(|p| { - let stripped_prefix_path = - p.strip_prefix(¤t_dir).unwrap_or_else(|_| p); - path_prefix_in_plugins.join(stripped_prefix_path) + .collect(); + let update_paths: Vec<PathBuf> = update_events + .drain(..) + .map(|e| { + e.paths + .iter() + .map(|p| { + let stripped_prefix_path = + p.strip_prefix(¤t_dir).unwrap_or_else(|_| p); + path_prefix_in_plugins.join(stripped_prefix_path) + }) + .collect() }) - .collect() - }).collect(); - let delete_paths: Vec<PathBuf> = delete_events.drain(..).map(|e| { - e - .paths - .iter() - .map(|p| { - let stripped_prefix_path = - p.strip_prefix(¤t_dir).unwrap_or_else(|_| p); - path_prefix_in_plugins.join(stripped_prefix_path) + .collect(); + let delete_paths: Vec<PathBuf> = delete_events + .drain(..) + .map(|e| { + e.paths + .iter() + .map(|p| { + let stripped_prefix_path = + p.strip_prefix(¤t_dir).unwrap_or_else(|_| p); + path_prefix_in_plugins.join(stripped_prefix_path) + }) + .collect() }) - .collect() - }).collect(); + .collect(); let _ = senders.send_to_plugin(PluginInstruction::Update(vec![ (None, None, Event::FileSystemRead(read_paths)), (None, None, Event::FileSystemCreate(create_paths)), @@ -80,10 +97,14 @@ pub fn watch_filesystem(senders: ThreadSenders, zellij_cwd: &Path) -> Result<Deb (None, None, Event::FileSystemDelete(delete_paths)), ])); }, - Err(errors) => errors.iter().for_each(|error| log::error!("watch error: {error:?}")), - } + Err(errors) => errors + .iter() + .for_each(|error| log::error!("watch error: {error:?}")), + }, )?; - debouncer.watcher().watch(zellij_cwd, RecursiveMode::Recursive)?; + debouncer + .watcher() + .watch(zellij_cwd, RecursiveMode::Recursive)?; Ok(debouncer) } diff --git a/zellij-utils/src/lib.rs b/zellij-utils/src/lib.rs index 7764f7601..b07fe8bdc 100644 --- a/zellij-utils/src/lib.rs +++ b/zellij-utils/src/lib.rs @@ -20,6 +20,6 @@ pub mod logging; // Requires log4rs #[cfg(not(target_family = "wasm"))] pub use ::{ - anyhow, async_channel, async_std, clap, interprocess, lazy_static, libc, miette, nix, notify_debouncer_full, - regex, serde, signal_hook, tempfile, termwiz, vte, + anyhow, async_channel, async_std, clap, interprocess, lazy_static, libc, miette, nix, + notify_debouncer_full, regex, serde, signal_hook, tempfile, termwiz, vte, }; |