dartboard_resume/bin/dartboard_resume.dart

56 lines
1.8 KiB
Dart
Raw Normal View History

import 'dart:async';
import 'dart:convert';
import 'dart:io';
import 'package:dartboard_resume/dartboard_parser.dart';
import 'package:dartboard_resume/render.dart';
import 'package:hotreloader/hotreloader.dart';
import 'package:logging/logging.dart' as logging;
import 'package:toml/toml.dart';
StreamSubscription<FileSystemEvent>? fileStreamSub;
StreamSubscription<String>? stdinStreamSub;
Future<void> main(List<String> 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);
}
if (event == "p") {
stdout.writeln("Current toml map:");
stdout.writeln(TomlDocument.loadSync(tomlFilePath).toMap());
final dartboardData = DartboardData.fromToml(tomlFilePath);
dartboardData.miscList.forEach(stdout.writeln);
}
},
);
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);
}
}