paint method

void paint()

Draws the current frame, replacing whatever the spinner drew last.

Implementation

void paint() {
  if (!_running) return;

  final plain = '$_pad${_frames[_frame]} ${describe?.call() ?? label}  '
      '${_format(_elapsed.elapsed)}';
  // A line wider than the pane wraps, and `\r` only returns to the start of
  // the *last* row — so the erase would miss everything above it and every
  // repaint would scroll another row. Truncating keeps the animation on one
  // line, which is the only shape it can clean up after.
  final trimmed = plain.length <= _columns
      ? plain
      : '${plain.substring(0, _columns - 1)}…';

  sink().write('\r${_styled(trimmed)}');
  // Remembered so the next erase clears exactly this many columns; a shorter
  // following line would otherwise leave the tail of this one behind.
  _painted = trimmed.length;
}