lastFrame function

String lastFrame(
  1. String line
)

The final state of a line that redrew itself in place.

A child process animates progress by returning to column 0 with a bare \r and painting over what it wrote. Left in the stream that would overwrite the prefix saying which service the line came from, so it cannot simply be passed through — but treating \r as a line break is the other extreme: every frame of the animation becomes a permanent line, and starting two services turns a single spinner into a wall of ⠋ Retrieving…, ⠙ Retrieving…, ✓ Retrieved.

A carriage return means replace what I just drew. So only the text after the last one survives, which is that line's finished state.

Implementation

String lastFrame(String line) {
  final text = _withoutLineEnding(line);
  final lastReturn = text.lastIndexOf('\r');

  return (lastReturn == -1 ? text : text.substring(lastReturn + 1)).trim();
}