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 {
    sb.write(ansiDefault);
    return sb.toString();
  }
}