Add main class.
[xudocci.git] / src / main / java / net / pterodactylus / xdcc / ui / stdin / CommandReader.java
index 46b22ba..381c519 100644 (file)
@@ -19,6 +19,9 @@ package net.pterodactylus.xdcc.ui.stdin;
 
 import static com.google.common.collect.FluentIterable.from;
 import static java.util.Arrays.asList;
+import static net.pterodactylus.xdcc.ui.stdin.Ansi.bold;
+import static net.pterodactylus.xdcc.ui.stdin.Ansi.green;
+import static net.pterodactylus.xdcc.ui.stdin.Ansi.red;
 import static net.pterodactylus.xdcc.ui.stdin.Command.TO_NAME;
 
 import java.io.BufferedReader;
@@ -38,6 +41,7 @@ import net.pterodactylus.xdcc.core.event.MessageReceived;
 import net.pterodactylus.xdcc.data.Download;
 
 import com.google.common.base.Joiner;
+import com.google.common.base.Optional;
 import com.google.common.collect.ImmutableList;
 import com.google.common.collect.ImmutableSet;
 import com.google.common.eventbus.Subscribe;
@@ -130,7 +134,7 @@ public class CommandReader extends AbstractExecutionThreadService {
        public void downloadStarted(DownloadStarted downloadStarted) {
                Download download = downloadStarted.download();
                try {
-                       writeLine(String.format("Download of %s (from %s, %s) has started.", download.pack().name(), download.bot().name(), download.bot().network().name()));
+                       writeLine(String.format("Download of %s (from %s, %s) has started.", bold(download.pack().name()), download.bot().name(), download.bot().network().name()));
                } catch (IOException ioe1) {
                        /* ignore. */
                }
@@ -146,7 +150,7 @@ public class CommandReader extends AbstractExecutionThreadService {
        public void downloadFinished(DownloadFinished downloadFinished) {
                Download download = downloadFinished.download();
                try {
-                       writeLine(String.format("Download of %s (from %s, %s) has finished, at %s/s.", download.pack().name(), download.bot().name(), download.bot().network().name(), f(download.dccReceiver().overallRate())));
+                       writeLine(green(String.format("Download of %s (from %s, %s) has finished, at %s/s.", download.pack().name(), download.bot().name(), download.bot().network().name(), f(download.dccReceiver().overallRate()))));
                } catch (IOException ioe1) {
                        /* ignore. */
                }
@@ -162,7 +166,7 @@ public class CommandReader extends AbstractExecutionThreadService {
        public void downloadFailed(DownloadFailed downloadFailed) {
                Download download = downloadFailed.download();
                try {
-                       writeLine(String.format("Download of %s (from %s, %s) has failed at %.1f%% and %s/s.", download.filename(), download.bot().name(), download.bot().network().name(), download.dccReceiver().progress() * 100.0 / download.dccReceiver().size(), f(download.dccReceiver().overallRate())));
+                       writeLine(red(String.format("Download of %s (from %s, %s) has failed at %.1f%% and %s/s.", download.filename(), download.bot().name(), download.bot().network().name(), download.dccReceiver().progress() * 100.0 / download.dccReceiver().size(), f(download.dccReceiver().overallRate()))));
                } catch (IOException ioe1) {
                        /* ignore. */
                }
@@ -251,4 +255,21 @@ public class CommandReader extends AbstractExecutionThreadService {
                return String.format("%dB", number);
        }
 
+       /**
+        * Formats the given number of seconds into a more easily readable string.
+        *
+        * @param seconds
+        *              The number of seconds
+        * @return The formatted time, or “unknown” if the time is unknown
+        */
+       static String t(Optional<Long> seconds) {
+               if (!seconds.isPresent()) {
+                       return "unknown";
+               }
+               if (seconds.get() > 3600) {
+                       return String.format("%02d:%02d:%02d", seconds.get() / 3600, (seconds.get() / 60) % 60, seconds.get() % 60);
+               }
+               return String.format("%02d:%02d", (seconds.get() / 60) % 60, seconds.get() % 60);
+       }
+
 }