Improvement: add a text ui who display info in a single line
This commit is contained in:
@@ -525,7 +525,7 @@ public class Server extends Thread implements HostnameVerifier, X509TrustManager
|
||||
fos.close();
|
||||
inStrm.close();
|
||||
long end = new Date().getTime();
|
||||
System.out.println(String.format("File downloaded at %.1f kB/s", ((float) (size / 1000)) / ((float) (end - start) / 1000)));
|
||||
this.log.debug(String.format("File downloaded at %.1f kB/s", ((float) (size / 1000)) / ((float) (end - start) / 1000)));
|
||||
this.lastRequestTime = new Date().getTime();
|
||||
return 0;
|
||||
}
|
||||
|
||||
60
src/com/sheepit/client/standalone/GuiTextOneLine.java
Normal file
60
src/com/sheepit/client/standalone/GuiTextOneLine.java
Normal file
@@ -0,0 +1,60 @@
|
||||
package com.sheepit.client.standalone;
|
||||
|
||||
import com.sheepit.client.Gui;
|
||||
|
||||
public class GuiTextOneLine implements Gui {
|
||||
private int rendered;
|
||||
private int remaining;
|
||||
private String status;
|
||||
private String line;
|
||||
|
||||
public GuiTextOneLine() {
|
||||
rendered = 0;
|
||||
remaining = 0;
|
||||
status = "";
|
||||
line = "";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void start() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stop() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void status(String msg_) {
|
||||
status = msg_;
|
||||
updateLine();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void error(String msg_) {
|
||||
status = "Error " + msg_;
|
||||
updateLine();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void AddFrameRendered() {
|
||||
rendered += 1;
|
||||
updateLine();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void framesRemaining(int n_) {
|
||||
remaining = n_;
|
||||
updateLine();
|
||||
}
|
||||
|
||||
private void updateLine() {
|
||||
int charToRemove = line.length();
|
||||
|
||||
System.out.print("\r");
|
||||
line = String.format("%s | Frame rendered: %d remaining: %d", status, rendered, remaining);
|
||||
System.out.print(line);
|
||||
for (int i = line.length(); i <= charToRemove; i++) {
|
||||
System.out.print(" ");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -80,6 +80,9 @@ public class Worker {
|
||||
@Option(name = "-extras", usage = "Extras data push on the authentication request", required = false)
|
||||
private String extras = null;
|
||||
|
||||
@Option(name = "-ui", usage = "Specify the user interface to you use, default 'text', available 'oneline', 'text'", required = false)
|
||||
private String ui_type = "text";
|
||||
|
||||
@Option(name = "--version", usage = "Display application version", required = false)
|
||||
private boolean display_version = false;
|
||||
|
||||
@@ -248,7 +251,17 @@ public class Worker {
|
||||
|
||||
Log.getInstance(config).debug("client version " + config.getJarVersion());
|
||||
|
||||
Gui gui = new GuiText();
|
||||
Gui gui;
|
||||
if (ui_type.equals("oneline")) {
|
||||
if (config.getPrintLog()) {
|
||||
System.out.println("OneLine ui can not be used if the verbose mode is enable");
|
||||
System.exit(2);
|
||||
}
|
||||
gui = new GuiTextOneLine();
|
||||
}
|
||||
else {
|
||||
gui = new GuiText();
|
||||
}
|
||||
Client cli = new Client(gui, config, server);
|
||||
|
||||
ShutdownHook hook = new ShutdownHook(cli);
|
||||
|
||||
Reference in New Issue
Block a user