render method

  1. @override
void render(
  1. Console console,
  2. ActivityIndicatorState state
)
override

Render the activity indicator.

The state is the current state of the activity indicator.

The buffer is the buffer to render the activity indicator.

Implementation

@override
void render(Console console, ActivityIndicatorState state) {
  final bar = switch (state) {
    ActivityIndicatorState(isReady: true) => '[]'.consoleText(),
    ActivityIndicatorState(isSuccess: true) =>
      success.consoleText(style: ConsoleStyle.success),
    ActivityIndicatorState(isFailure: true) =>
      failure.consoleText(style: ConsoleStyle.error),
    ActivityIndicatorState(isActive: true, tick: final tick) =>
      renderActiveBar(tick, console.activityBarWidth),
    _ => throw StateError('The activity indicator is not active.'),
  };
  final title = this.title?.consoleText();
  final text = title == null ? bar : title + ' '.consoleText() + bar;

  console.output(text, newline: true);
}