ratatui_toolkit/services/file_watcher/constructors/
for_directory.rs

1//! Convenience constructor for directory watching.
2
3use crate::services::file_watcher::{FileWatcher, WatchConfig, WatchMode};
4
5impl FileWatcher {
6    /// Create a file watcher preset for watching a directory recursively.
7    ///
8    /// Uses `WatchMode::Recursive` with 200ms debounce (longer to handle
9    /// rapid changes during builds or git operations).
10    ///
11    /// # Errors
12    ///
13    /// Returns a `notify::Error` if the watcher cannot be created.
14    ///
15    /// # Example
16    ///
17    /// ```no_run
18    /// use ratatui_toolkit::services::file_watcher::FileWatcher;
19    /// use std::path::Path;
20    ///
21    /// let mut watcher = FileWatcher::for_directory().unwrap();
22    /// watcher.watch(Path::new("./src")).unwrap();
23    /// ```
24    pub fn for_directory() -> Result<Self, notify::Error> {
25        Self::with_config(WatchConfig {
26            mode: WatchMode::Recursive,
27            debounce_ms: 200,
28        })
29    }
30}