update method

void update(
  1. int progress
)

Updates the Progress Bar with a progress of progress.

Implementation

void update(int progress) {
  if (progress == current) {
    return;
  }

  current = progress;

  var ratio = progress / complete;
  var percent = (ratio * 100).toInt();

  var digits = percent.toString().length;

  var w = Console.columns - digits - 4;

  var count = (ratio * w).toInt();
  var before = '${percent}% [';
  var after = ']';

  var out = StringBuffer(before);

  for (var x = 1; x < count; x++) {
    out.write('=');
  }

  out.write('>');

  for (var x = count; x < w; x++) {
    out.write(' ');
  }

  out.write(after);

  if (out.length - 1 == Console.columns) {
    var it = out.toString();

    out.clear();
    out.write(it.substring(0, it.length - 2) + ']');
  }

  Console.overwriteLine(out.toString());
}