truncateLine method

String truncateLine([
  1. int? spacing,
  2. String suffix = '…'
])

Truncates a line to fit within the console window width

Implementation

String truncateLine([int? spacing, String suffix = '…']) {
  spacing ??= console.spacing;
  final windowWidth = console.windowWidth;

  // Join all lines into a single string
  final line = split('\n').join(' ');

  // If the line is longer than the window width, truncate it
  if (line.strip().length > windowWidth - spacing) {
    return '${line.substring(0, windowWidth - spacing)}$suffix';
  }
  return line;
}