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;
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;
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. */
}
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. */
}
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. */
}
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);
+ }
+
}