start method
Starts watching. Runs until stop is called or the process exits.
Implementation
Future<void> start() async {
if (_running) return;
_running = true;
final file = File(specPath);
if (!await file.exists()) {
_error('Spec file not found: $specPath');
return;
}
_log('👁️ Watching: $specPath');
_log(' Press Ctrl+C to stop.\n');
// Initial build
await _rebuild();
// Watch parent directory (more reliable cross-platform)
final dir = file.parent;
_sub = dir.watch(events: FileSystemEvent.all).listen(
_onEvent,
onError: (Object error) {
_error('Watcher error: $error');
_restart();
},
);
// Handle Ctrl+C
ProcessSignal.sigint.watch().listen((_) async {
await stop();
exit(0);
});
// Keep process alive
await _sub!.asFuture<void>().catchError((_) {});
}