render method

AdvancedProgressBar render ()

Implementation

AdvancedProgressBar render() {
  if(this.max == 0) return this;

  Duration difference = DateTime.now().difference(this.started);
  int x = int.parse((difference.inMilliseconds / 1000).toString().split(".")[1]);

  String percent = ((this.value / this.max) * 100).toStringAsFixed(2) + "%";

  if(percentage_decimal_places < 1) while(percent.length < 4) percent = " " + percent;
  else while(percent.length < 5 + percentage_decimal_places) percent = " " + percent;

  int m = 10;
  int symbols = ((this.value / this.max) * m).toInt();

  var out = StringBuffer("[");

  for (int x = 0; x < symbols; x++) out.write("=");

  out.write(">");

  for (int x = symbols; x < m; x++) out.write(" ");
  out.write("] ${(x < 250 ? "-" : x < 500 ? "\\" : x < 750 ? "|" : "/")} $percent ${(difference.inSeconds + 1).toString()} seconds ${this.actual != null && this.actual != "" ? this.actual : ""}");

  Console.overwriteLine(out.toString());

  return this;
}