import 'dart:async'; import 'dart:convert'; import 'dart:io'; import 'package:dartboard_resume/render.dart'; import 'package:hotreloader/hotreloader.dart'; import 'package:logging/logging.dart' as logging; StreamSubscription? fileStreamSub; StreamSubscription? stdinStreamSub; Future main(List arguments) async { const String tomlFilePath = "resume.toml"; logging.hierarchicalLoggingEnabled = true; HotReloader.logLevel = logging.Level.INFO; final HotReloader reloader = await HotReloader.create(); stdin.lineMode = false; stdin.echoMode = false; stdin.echoNewlineMode = false; stdinStreamSub = stdin.transform(const Utf8Decoder()).transform(const LineSplitter()).listen( (event) { if (event == "r") { stdout.writeln("Triggering pdf render..."); renderPdf(tomlFilePath, force: true); } }, ); ProcessSignal.sigint.watch().listen((_) { stdout.writeln('SIGINT received. Exiting gracefully...'); fileStreamSub?.cancel(); stdinStreamSub?.cancel(); // Perform cleanup or other necessary actions here reloader.stop(); exit(0); // Exit with code 0 to indicate a successful termination }); if (FileSystemEntity.isWatchSupported) { final fileStream = File(tomlFilePath).watch(events: FileSystemEvent.modify); fileStreamSub = fileStream.listen((e) { renderPdf(tomlFilePath); }); stdout.writeln('Watching for file changes.'); } else { renderPdf(tomlFilePath); } }