trim method

String trim(
  1. String string
)

Implementation

String trim(String string) {
  final spacerCounts = RegExp(r'\^').allMatches(string).length;
  final max = maxWidth - (spacerCounts * 2) - 1;
  final trimmed = string.split('\n').first.split('').take(max).toList();

  if (trimmed.length < string.length) {
    trimmed.add('…');
  }

  return trimmed.join().replaceAll(RegExp(r'\^'), '$invisible  $invisible');
}