Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,14 @@ protected String etaString(ProgressState progress) {

protected String percentage(ProgressState progress) {
String res;
if (progress.max <= 0 || progress.indefinite) res = "? %";
else res = String.valueOf((int) Math.floor(100.0 * progress.current / progress.max)) + "%";
if (progress.getMax() <= 0 || progress.isIndefinite()) res = "? %";
else res = String.valueOf((int) Math.floor(100.0 * progress.getCurrent() / progress.getMax())) + "%";
return Util.repeat(' ', 4 - res.length()) + res;
}

protected String ratio(ProgressState progress) {
String m = progress.indefinite ? "?" : String.valueOf(progress.max / unitSize);
String c = String.valueOf(progress.current / unitSize);
String m = progress.isIndefinite() ? "?" : String.valueOf(progress.getMax() / unitSize);
String c = String.valueOf(progress.getCurrent() / unitSize);
return Util.repeat(' ', m.length() - c.length()) + c + "/" + m + unitName;
}

Expand All @@ -102,7 +102,7 @@ protected String speed(ProgressState progress) {

if (elapsedSeconds == 0)
return "?" + unitName + suffix;
double speed = (double) (progress.current - progress.start) / elapsedInUnit;
double speed = (double) (progress.getCurrent() - progress.getStart()) / elapsedInUnit;
double speedWithUnit = speed / unitSize;
return speedFormat.format(speedWithUnit) + unitName + suffix;
}
Expand All @@ -128,7 +128,7 @@ public String render(ProgressState progress, int maxLength) {
+ Util.formatDuration(progress.getTotalElapsed())
+ (isEtaShown ? " / " + etaString(progress) : "")
+ ") "
+ speedString + progress.extraMessage;
+ speedString + progress.getExtraMessage();
int suffixLength = getStringDisplayLength(suffix);
// trim excessive suffix
if (suffixLength > maxSuffixLength) {
Expand All @@ -142,16 +142,16 @@ public String render(ProgressState progress, int maxLength) {
sb.append(prefix);

// case of indefinite progress bars
if (progress.indefinite) {
int pos = (int)(progress.current % length);
if (progress.isIndefinite()) {
int pos = (int)(progress.getCurrent() % length);
sb.append(Util.repeat(style.space, pos));
sb.append(style.block);
sb.append(Util.repeat(style.space, length - pos - 1));
}
// case of definite progress bars
else {
sb.append(Util.repeat(style.block, progressIntegralPart(progress, length)));
if (progress.current < progress.max) {
if (progress.getCurrent() < progress.getMax()) {
int fraction = progressFractionalPart(progress, length);
if (fraction != 0) {
sb.append(style.fractionSymbols.charAt(fraction));
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/me/tongfei/progressbar/ProgressUpdateAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,20 @@ class ProgressUpdateAction implements Runnable {
this.consumer = consumer;
this.continuousUpdate = continuousUpdate;
this.clearDisplayOnFinish = clearDisplayOnFinish;
this.last = progress.start;
this.last = progress.getStart();
this.first = true;
}

void refresh() {
if (continuousUpdate || (progress.current > last))
if (continuousUpdate || (progress.getCurrent() > last))
forceRefresh();
// else do nothing: only print when actual progress is made (#91).
}

public void forceRefresh() {
String rendered = renderer.render(progress, consumer.getMaxRenderedLength());
consumer.accept(rendered);
last = progress.current;
last = progress.getCurrent();
}

public void run() {
Expand All @@ -47,8 +47,8 @@ public void run() {
first = false;
}
else {
if (!progress.paused) refresh();
if (!progress.alive) {
if (!progress.isPaused()) refresh();
if (!progress.isAlive()) {
forceRefresh();
if (clearDisplayOnFinish) consumer.clear();
consumer.close();
Expand Down