Buffer.fromLines constructor

Buffer.fromLines(
  1. Iterable<Line> lines
)

Creates a new buffer from the given lines.

The width and height must be non-negative.

Implementation

factory Buffer.fromLines(Iterable<Line> lines) {
  final lines_ = List.of(lines);
  final height = lines_.length;
  final width = lines_.fold(0, (width, line) => math.max(width, line.width));

  final buffer = Buffer(width, height);
  for (var y = 0; y < height; y++) {
    buffer.setLine(0, y, lines_.elementAt(y));
  }
  return buffer;
}