run<T> static method

Future<T> run<T>(
  1. String label,
  2. Future<T> body(), {
  3. String describe()?,
})

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, {
  String Function()? describe,
}) async {
  if (!supported || active != null) return body();

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