update method

void update(
  1. int progress
)

Updates the Progress Bar with a progress of progress.

Implementation

void update(
  final int progress,
) {
  if (progress != current) {
    current = progress;
    final ratio = progress / complete;
    final percent = (ratio * 100).toInt();
    final digits = percent.toString().length;
    final w = console.columns - digits - 4;
    final count = (ratio * w).toInt();
    final before = '$percent% [';
    const after = ']';
    final out = StringBuffer(before);
    for (int x = 1; x < count; x++) {
      out.write('=');
    }
    out.write('>');
    for (int x = count; x < w; x++) {
      out.write(' ');
    }
    out.write(after);
    if (out.length - 1 == console.columns) {
      final it = out.toString();
      out.clear();
      out.write(it.substring(0, it.length - 2) + ']');
    }
    console.overwrite_line(out.toString());
  }
}