toString method

  1. @override
String toString()
override

Colors and styles are taken from: https://en.wikipedia.org/wiki/ANSI_escape_code

Implementation

@override
String toString() {
  final StringBuffer _sb = StringBuffer(ansiEsc);

  if (italic) {
    _sb.write('3;');
  }

  if (foregroundColor != null) {
    _sb.write('38;5;${foregroundColor}m');
  } else if (backgroundColor != null) {
    _sb.write('48;5;${backgroundColor}m');
  }

  if (_sb.length == ansiEsc.length) {
    return '';
  } else {
    return _sb.toString();
  }
}