truncatePad function

String truncatePad(
  1. String text,
  2. int width
)

Truncates text to width and pads to fill remaining space.

Combines truncation and padding for fixed-width column rendering.

Example:

truncatePad('Hello World', 8); // 'Hello W…'
truncatePad('Hi', 8); // 'Hi      '

Implementation

String truncatePad(String text, int width) {
  if (text.length <= width) return padRight(text, width);
  if (width <= 1) return text.substring(0, width);
  return '${text.substring(0, width - 1)}…';
}