docs: add basic code samples
This commit is contained in:
parent
0dc78afb1c
commit
c2561d87ef
4 changed files with 160 additions and 0 deletions
29
README.md
29
README.md
|
|
@ -125,6 +125,35 @@ const nightwatch = @import("nightwatch");
|
|||
|
||||
You now have programmatic access to the tracking engine.
|
||||
|
||||
### Example
|
||||
|
||||
```zig
|
||||
const nightwatch = @import("nightwatch");
|
||||
const std = @import("std");
|
||||
|
||||
const H = struct {
|
||||
handler: nightwatch.Default.Handler,
|
||||
|
||||
const vtable = nightwatch.Default.Handler.VTable{ .change = change, .rename = rename };
|
||||
|
||||
fn change(_: *nightwatch.Default.Handler, path: []const u8, event: nightwatch.EventType, _: nightwatch.ObjectType) error{HandlerFailed}!void {
|
||||
std.debug.print("{s} {s}\n", .{ @tagName(event), path });
|
||||
}
|
||||
|
||||
fn rename(_: *nightwatch.Default.Handler, src: []const u8, dst: []const u8, _: nightwatch.ObjectType) error{HandlerFailed}!void {
|
||||
std.debug.print("rename {s} -> {s}\n", .{ src, dst });
|
||||
}
|
||||
};
|
||||
|
||||
var h = H{ .handler = .{ .vtable = &H.vtable } };
|
||||
var watcher = try nightwatch.Default.init(allocator, &h.handler);
|
||||
defer watcher.deinit();
|
||||
try watcher.watch("/path/to/dir");
|
||||
// watcher delivers events on a background thread until deinit()
|
||||
```
|
||||
|
||||
See the [`examples/`](examples/) directory for complete, buildable programs.
|
||||
|
||||
---
|
||||
|
||||
# CLI Usage
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue