blocks method

void blocks(
  1. List<({LiveBlock block, String label})> blocks
)

Writes each labelled block, adding [device] prefixes when there is more than one.

Implementation

void blocks(List<({String label, LiveBlock block})> blocks) {
  if (blocks.length == 1) {
    block(blocks.single.block);
    return;
  }
  final int width = blocks
      .map((entry) => entry.label.length)
      .fold(0, (a, b) => a > b ? a : b);
  for (final ({String label, LiveBlock block}) entry in blocks) {
    block(entry.block, prefix: '[${entry.label}]'.padRight(width + 4));
  }
}