osal.notifier #
Notifier
A file system notification system for V that provides real-time monitoring of file system events using fswatch
.
Dependencies
fswatch
: Must be installed on your system. The notifier will check for its presence and return an error if not found.
Features
- Monitor file system events (create, modify, delete, rename)
- Multiple watch paths support
- Customizable event callbacks
- Clean start/stop functionality
Usage Example
import freeflowuniverse.herolib.osal.notifier
// Define callback function for file events
fn on_file_change(event notifier.NotifyEvent, path string) {
match event {
.create { println('File created: ${path}') }
.modify { println('File modified: ${path}') }
.delete { println('File deleted: ${path}') }
.rename { println('File renamed: ${path}') }
}
}
fn main() {
// Create a new notifier instance
mut n := notifier.new('my_watcher')!
// Add a path to watch
n.add_watch('/path/to/watch', on_file_change)!
// Start watching
n.start()!
// ... your application logic ...
// Stop watching when done
n.stop()
}
fn new #
fn new(name string) !&Notifier
new creates a new Notifier instance
type NotifyCallback #
type NotifyCallback = fn (event NotifyEvent, path string, args map[string]string)
NotifyCallback is the function signature for event callbacks
enum NotifyEvent #
enum NotifyEvent {
create
modify
delete
rename
}
NotifyEvent represents the type of file system event
struct Notifier #
struct Notifier {
pub mut:
name string
watch_list []WatchEntry
is_watching bool
args map[string]string
}
Notifier manages file system notifications using fswatch
fn (Notifier) add_watch #
fn (mut n Notifier) add_watch(path string, callback NotifyCallback) !
add_watch adds a path to watch with an associated callback
fn (Notifier) remove_watch #
fn (mut n Notifier) remove_watch(path string) !
remove_watch removes a watched path
fn (Notifier) start #
fn (mut n Notifier) start() !
start begins watching for events
fn (Notifier) stop #
fn (mut n Notifier) stop()
stop stops watching for events