render method
Renders this span to the buffer.
For primitive spans (PlainText, AnsiStyled, etc.), override this to write directly to the buffer.
For composite spans that override build, the default implementation delegates to the built span.
Implementation
@override
void render(ConsoleMessageBuffer buffer) {
final c = child;
if (c == null) return;
final temp = buffer.createChildBuffer();
c.render(temp);
final content = temp.toString();
final lines = content.isEmpty ? <String>[] : content.split('\n');
if (lines.isEmpty) return;
final chars = BoxBorderChars.fromStyle(style);
// Strip ANSI escape codes when calculating visible width
final visibleWidths = lines.map((l) => stripAnsiCodes(l).length).toList();
final maxWidth = visibleWidths.reduce((a, b) => a > b ? a : b);
final paddingStr = ' ' * padding;
final innerWidth = maxWidth + (padding * 2);
// Top border
buffer.write(
chars.topLeft + chars.horizontal * innerWidth + chars.topRight,
foreground: borderColor,
);
buffer.write('\n');
// Content lines
for (var i = 0; i < lines.length; i++) {
final line = lines[i];
final visibleWidth = visibleWidths[i];
final padAmount = maxWidth - visibleWidth;
buffer.write(chars.vertical, foreground: borderColor);
buffer.write(paddingStr + line + ' ' * padAmount + paddingStr);
buffer.write(chars.vertical, foreground: borderColor);
buffer.write('\n');
}
// Bottom border
buffer.write(
chars.bottomLeft + chars.horizontal * innerWidth + chars.bottomRight,
foreground: borderColor,
);
}