2024-09-07 14:42:32 -06:00
|
|
|
import 'dart:async';
|
|
|
|
import 'dart:convert';
|
|
|
|
import 'dart:io';
|
|
|
|
|
2024-09-10 13:14:00 -06:00
|
|
|
import 'package:dartboard_resume/dartboard_parser.dart';
|
2024-09-07 14:42:32 -06:00
|
|
|
import 'package:dartboard_resume/render.dart';
|
|
|
|
import 'package:hotreloader/hotreloader.dart';
|
|
|
|
import 'package:logging/logging.dart' as logging;
|
2024-09-10 13:14:00 -06:00
|
|
|
import 'package:toml/toml.dart';
|
2024-09-07 14:42:32 -06:00
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
2024-09-10 13:14:00 -06:00
|
|
|
if (event == "p") {
|
|
|
|
stdout.writeln("Current toml map:");
|
|
|
|
stdout.writeln(TomlDocument.loadSync(tomlFilePath).toMap());
|
|
|
|
final dartboardData = DartboardData.fromToml(tomlFilePath);
|
|
|
|
dartboardData.miscList.forEach(stdout.writeln);
|
|
|
|
}
|
2024-09-07 14:42:32 -06:00
|
|
|
},
|
|
|
|
);
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|