maxLineWidth function

int maxLineWidth(
  1. String s
)

Returns the maximum display width across all lines in s.

The input is treated as newline-separated rows; width resets after each newline. This matches how layout code interprets terminal cell widths.

Implementation

int maxLineWidth(String s) {
  final normalized = s.replaceAll('\r\n', '\n');
  var maxWidth = 0;
  for (final line in normalized.split('\n')) {
    final w = stringWidth(line);
    if (w > maxWidth) maxWidth = w;
  }
  return maxWidth;
}