createBox method

  1. @visibleForTesting
String createBox(
  1. String header,
  2. List<String> parts,
  3. AnsiPen borderPen
)

Implementation

@visibleForTesting
String createBox(String header, List<String> parts, AnsiPen borderPen) {
  final buffer = StringBuffer();
  buffer.write(borderPen(borderStyle.downAndRight +
      borderStyle.horizontal +
      header.replaceAll(' ', borderStyle.horizontal) +
      borderStyle.horizontal * (lineLength - header.length - 3) +
      borderStyle.downAndLeft));
  buffer.writeln();
  for (final (index, part) in parts.indexed) {
    for (final line in part.split('\n')) {
      final vertical = borderPen(borderStyle.vertical);
      buffer.write(vertical);
      buffer.write(' ');
      if (line.length <= lineLength - 2) {
        buffer.write(line.padRight(lineLength - 3));
        buffer.write(vertical);
      } else {
        buffer.write(line);
      }
      buffer.writeln();
    }
    if (index < parts.length - 1) {
      buffer.writeln(borderPen(borderStyle.verticalAndRight +
          borderStyle.horizontal * (lineLength - 2) +
          borderStyle.verticalAndLeft));
    }
  }
  buffer.write(borderPen(borderStyle.upAndRight +
      borderStyle.horizontal * (lineLength - 2) +
      borderStyle.upAndLeft));
  return buffer.toString();
}