onEvent method

  1. @override
void onEvent(
  1. PipeEvent event
)
override

Implementation

@override
void onEvent(PipeEvent event) {
  switch (event) {
    case RunStarted started:
      _steps = started.allSteps;
      // The labels of the steps in a group start further right, and their times are still aligned with the rest
      _labelWidth = _steps.fold(0, (int width, StepState s) => max(width, s.depth * _levelWidth + Mansil.visibleWidth(s.step.label)));
      _pendingLines.addAll([...PipeFormat.title(started.info).map(_bold), ""]);

      _out.write(Mansil.hideCursor);
      // The cursor would stay hidden after the user stops the run with ctrl+c
      _interruptSubscription = ProcessSignal.sigint.watch().listen((ProcessSignal _) {
        _out.write(Mansil.showCursor);
        exit(130);
      });
      _timer = Timer.periodic(_frameInterval, (Timer _) {
        _frame++;
        _render();
      });
      _render();
    case StepStarted started:
      _printStageTitle(started.step);
      _render();
    case StepFinished _:
      // A step of a group stays in the live part until the whole group has finished
      while (_firstLiveStep < _steps.length && _steps[_firstLiveStep].isFinished) {
        StepState step = _steps[_firstLiveStep];
        _printStageTitle(step);
        _pendingLines.addAll(_finishedLines(step));
        _firstLiveStep++;
      }
      _render();
    case RunFinished finished:
      _timer?.cancel();
      _render();
      _out.writeln();
      _out.writeln(
        finished.result.hasFailures
            ? PipeFormat.color("X ${PipeFormat.summary(finished.result)}", Mansil.redFg, true)
            : PipeFormat.color("√ ${PipeFormat.summary(finished.result)}", Mansil.greenFg, true),
      );
      if (logFilePath != null) {
        _out.writeln(_dim("Log: $logFilePath"));
      }
      _out.write(Mansil.showCursor);
    default:
      // The rest of the events change the state of the running step, which is drawn on the next frame
      break;
  }
}