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 _sb = StringBuffer();

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

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

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