createBox method
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();
}