run<T> static method

Future<T> run<T>(
  1. String label,
  2. Future<T> body()
)

Runs body with a spinner labelled label.

The spinner is always stopped, including when body throws, so a failure never leaves a half-drawn line on the terminal.

Implementation

static Future<T> run<T>(String label, Future<T> Function() body) async {
  if (!supported || active != null) return body();

  final spinner = Spinner._(label, '  ' * ColorizeLogger.indentLevel);
  active = spinner;
  spinner._start();
  try {
    return await body();
  } finally {
    spinner._stop();
    active = null;
  }
}