run method
Runs the TUI program.
This method:
- Sets up the terminal
- Initializes the model
- Starts the event loop
- Waits for quit signal
- Cleans up and exits
Returns when the program exits (via Cmd.quit or interrupt).
If ProgramOptions.catchPanics is true (default), exceptions are caught, the terminal is restored, and a formatted error is printed.
Implementation
Future<void> run() async {
if (_running) {
throw StateError('Program is already running');
}
_running = true;
_cancelled = false;
_cleanedUp = false;
_cleanupErrors.clear();
_runCompleter = Completer<void>();
_panic = null;
_panicStackTrace = null;
if (_options.captureOutput) {
await runZoned(
_runInner,
zoneSpecification: ZoneSpecification(
print: (self, parent, zone, line) {
// Intercept print() and dispatch as a message instead of
// writing to stdout (which would corrupt the TUI display).
if (_running) {
send(CapturedOutputMsg(line));
}
},
),
);
} else {
await _runInner();
}
}