From c593b23bf8a5fa054ecdd18772d643dc6b2f8b0d Mon Sep 17 00:00:00 2001 From: Laurent Clouet Date: Thu, 20 Nov 2014 17:50:23 +0000 Subject: [PATCH] Improvement: add a text ui who display info in a single line --- src/com/sheepit/client/Server.java | 2 +- .../client/standalone/GuiTextOneLine.java | 60 +++++++++++++++++++ src/com/sheepit/client/standalone/Worker.java | 15 ++++- 3 files changed, 75 insertions(+), 2 deletions(-) create mode 100644 src/com/sheepit/client/standalone/GuiTextOneLine.java diff --git a/src/com/sheepit/client/Server.java b/src/com/sheepit/client/Server.java index 0f7c8bc..11b4a98 100644 --- a/src/com/sheepit/client/Server.java +++ b/src/com/sheepit/client/Server.java @@ -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; } diff --git a/src/com/sheepit/client/standalone/GuiTextOneLine.java b/src/com/sheepit/client/standalone/GuiTextOneLine.java new file mode 100644 index 0000000..c6c8b72 --- /dev/null +++ b/src/com/sheepit/client/standalone/GuiTextOneLine.java @@ -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(" "); + } + } +} diff --git a/src/com/sheepit/client/standalone/Worker.java b/src/com/sheepit/client/standalone/Worker.java index 1e10a36..7679f61 100644 --- a/src/com/sheepit/client/standalone/Worker.java +++ b/src/com/sheepit/client/standalone/Worker.java @@ -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);