-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
132 additions
and
276 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
#!/usr/bin/env -S v -n -w -gc none -cc tcc -d use_openssl -enable-globals run | ||
|
||
import freeflowuniverse.herolib.osal.notifier | ||
import os | ||
import time | ||
|
||
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 test directory and files | ||
test_dir := '/tmp/notifytest' | ||
if !os.exists(test_dir) { | ||
os.mkdir_all(test_dir)! | ||
os.write_file('${test_dir}/test.txt', 'initial content')! | ||
os.mkdir('${test_dir}/subdir')! | ||
os.write_file('${test_dir}/subdir/test2.txt', 'test content')! | ||
} | ||
|
||
// Create a new notifier | ||
mut n := notifier.new('test_watcher')! | ||
|
||
// Add files to watch | ||
n.add_watch('${test_dir}', on_file_change)! | ||
|
||
// Start watching | ||
n.start()! | ||
|
||
println('Watching files in ${test_dir} for 60 seconds...') | ||
println('Try these operations to test the notifier:') | ||
println('1. Modify a file: echo "new content" > ${test_dir}/test.txt') | ||
println('2. Create a file: touch ${test_dir}/newfile.txt') | ||
println('3. Delete a file: rm ${test_dir}/test.txt') | ||
println('4. Rename a file: mv ${test_dir}/test.txt ${test_dir}/renamed.txt') | ||
|
||
// Keep the program running for 60 seconds | ||
time.sleep(60 * time.second) | ||
|
||
// Clean up | ||
n.stop() | ||
println('\nWatch period ended.') | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.