hisma_console_monitor 0.5.0+1
hisma_console_monitor: ^0.5.0+1 copied to clipboard
Simple state machine monitor implementation that writes to the console for the Hisma package.
Simple monitor implementation for the Hisma package.
Features #
Prints out to console (or onto anything else you define. e.g. a logger) the machine and state structure of the hierarchical state machines of the program where (*) indicates the active states (for a more compact output you can use the [includeInactive] constructor argument set to false):

Getting started #
Create your state machines with hisma.
Usage #
Class level configuration #
You can enable [ConsoleMonitor] by adding a creator function that returns ConsoleMonitor to the list of monitor creators (example code from hisma examples) at class level:
Future<void> main() async {
Machine.monitorCreators = [
(machine) => ConsoleMonitor(machine),
];
await lightMachine.start();
play();
}
This will result that all state machine creation and active state changes will be monitored by ConsoleMonitor, writing out all active states of all hierarchical state machines of the program.
Instance level configuration #
Instance level configuration during machine construction
Configuring monitors also possible at instance level by declaring them in the machine constructor:
Machine<S, E, T> createColorMachine() => Machine<S, E, T>(
monitorCreators: [
(m) => ConsoleMonitor(m),
],
...
In this case only this machine instance will be monitored.
Instance level configuration of an already constructed machine
You can add monitors to an already existing machine using the addMonitors method:
final colorMachine = createColorMachine();
colorMachine.addMonitors([
(m) => ConsoleMonitor(m),
(m) => VisualMonitor(m),
]);
With this approach, just like in the previous case with configuring monitors in the machine constructor, only this machine instance will be monitored.
Printer #
One can easily modify how [ConsoleMonitor] prints out the active states, e.g. you can use your logger instead of printing to consoles. In the following example we add an extra separator line before each output of active states:
Future<void> main() async {
Machine.monitorCreators = [
(machine) => ConsoleMonitor(
machine,
printer: (str) {
print('-MONITOR----------------------------');
print(str);
},
),
];
await lightMachine.start();
play();
}
Additional information #
If you have any questions, comments please go to Hisma GitHub Discussions to start or join discussions.