Feature: in text UI, show downloads in a single-line (#250)

* Feature: show downloads in a single-line in text UIs
This commit is contained in:
Luis Uguina
2020-06-14 20:01:32 +10:00
committed by GitHub
parent 8736892565
commit fe69d6faa2
6 changed files with 82 additions and 10 deletions

View File

@@ -191,6 +191,12 @@ public class GuiSwing extends JFrame implements Gui {
}
}
@Override public void status(String msg, int progress, long size) {
if (activityWorking != null) {
this.activityWorking.setStatus(String.format("%s %d%%", msg, progress));
}
}
@Override public void setRenderingProjectName(String name_) {
if (activityWorking != null) {
this.activityWorking.setRenderingProjectName(name_);

View File

@@ -31,6 +31,7 @@ import sun.misc.SignalHandler;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Collections;
import java.util.Date;
public class GuiText implements Gui {
@@ -110,6 +111,11 @@ public class GuiText implements Gui {
}
}
@Override public void status(String msg, int progress, long size) {
System.out.print("\r");
System.out.print(String.format("%s %s", this.df.format(new Date()), showProgress(msg, progress, size)));
}
@Override public void error(String err_) {
System.out.println(String.format("ERROR: %s %s", this.df.format(new Date()), err_));
log.error("Error " + err_);
@@ -160,4 +166,28 @@ public class GuiText implements Gui {
@Override public void successfulAuthenticationEvent(String publickey) {
}
private String showProgress(String message, int progress, long size) {
StringBuilder progressBar = new StringBuilder(140);
progressBar
.append(message)
.append(" ")
.append(String.join("", Collections.nCopies(progress == 0 ? 2 : 2 - (int) (Math.log10(progress)), " ")))
.append(String.format("%d%% [", progress))
.append(String.join("", Collections.nCopies((int)(progress/5), "=")))
.append('>')
.append(String.join("", Collections.nCopies(20 - (int)(progress / 5), " ")))
.append(']');
if (size > 0) {
progressBar.append(String.format(" %dMB", (size / 1024 / 1024)));
}
// Once the process has completed, show the output in a new line
if (progress == 100) {
progressBar.append("\n");
}
return progressBar.toString();
}
}

View File

@@ -30,6 +30,7 @@ import sun.misc.SignalHandler;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Collections;
import java.util.Date;
public class GuiTextOneLine implements Gui {
@@ -122,12 +123,17 @@ public class GuiTextOneLine implements Gui {
}
}
@Override public void status(String msg, int progress, long size) {
status = showProgress(msg, progress, size);
updateLine();
}
@Override public void setRenderingProjectName(String name_) {
if (name_ == null || name_.isEmpty()) {
project = "";
}
else {
project = "Project \"" + name_ + "\" |";
project = name_ + " |";
}
updateLine();
}
@@ -154,7 +160,7 @@ public class GuiTextOneLine implements Gui {
}
@Override public void setRemainingTime(String time_) {
status = "(remaining " + time_ + ")";
status = "Rendering (remaining " + time_ + ")";
updateLine();
}
@@ -184,14 +190,42 @@ public class GuiTextOneLine implements Gui {
System.out.print("\r");
line = String.format("%s Frames: %d Points: %s | Queued uploads: %d%s | %s %s %s", df.format(new Date()), rendered,
creditsEarned != null ? creditsEarned : "unknown", this.uploadQueueSize,
(this.uploadQueueSize > 0 ? String.format(" (%.2fMB)", (this.uploadQueueVolume / 1024.0 / 1024.0)) : ""), project, computeMethod,
status + (exiting ? " (Exiting after all frames are uploaded)" : ""));
line = String.format("%s Frames: %d Points: %s | Upload Queue: %d%s | %%s %s %s", df.format(new Date()), rendered,
creditsEarned != null ? creditsEarned : "unknown", this.uploadQueueSize,
(this.uploadQueueSize > 0 ? String.format(" (%.2fMB)", (this.uploadQueueVolume / 1024.0 / 1024.0)) : ""), computeMethod,
status + (exiting ? " (Exiting after all frames are uploaded)" : ""));
if (line.length() + project.length() > 120) {
// If the line without the project name is already >120 characters (might happen if the user has thousands of frames and millions of points in the
// session + is exiting after all frames are uploaded) then set the line to 117c to avoid a negative number exception in substring function
int lineLength = (line.length() >= 120 ? 117 : line.length());
line = String.format(line, project.substring(0, 117 - lineLength) + "...");
}
else {
line = String.format(line, project);
}
System.out.print(line);
for (int i = line.length(); i <= charToRemove; i++) {
System.out.print(" ");
}
}
private String showProgress(String message, int progress, long size) {
StringBuilder progressBar = new StringBuilder(140);
progressBar
.append(message)
.append(String.join("", Collections.nCopies(progress == 0 ? 2 : 2 - (int) (Math.log10(progress)), " ")))
.append(String.format(" %d%%%% [", progress))
.append(String.join("", Collections.nCopies((int) (progress / 10), "=")))
.append('>')
.append(String.join("", Collections.nCopies(10 - (int) (progress / 10), " ")))
.append(']');
if (size > 0) {
progressBar.append(String.format(" %dMB", (size / 1024 / 1024)));
}
return progressBar.toString();
}
}