X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fxdcc%2Fui%2Fstdin%2FCommandReader.java;h=87678b5a613f7a6a56b7d53f259cd99299779043;hb=a488ccc7436f131efaf51e81f003f9a4862d1a74;hp=01d00516e1310c2b586f7e96c85e3fcccecbbdd2;hpb=5d31ca8229a8ad96822788015313bf5adada892e;p=xudocci.git diff --git a/src/main/java/net/pterodactylus/xdcc/ui/stdin/CommandReader.java b/src/main/java/net/pterodactylus/xdcc/ui/stdin/CommandReader.java index 01d0051..87678b5 100644 --- a/src/main/java/net/pterodactylus/xdcc/ui/stdin/CommandReader.java +++ b/src/main/java/net/pterodactylus/xdcc/ui/stdin/CommandReader.java @@ -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; @@ -59,6 +62,7 @@ public class CommandReader extends AbstractExecutionThreadService { /** The writer to write the results to. */ private final Writer writer; + private final Collection failedDownloads; /** * Creates a new command reader. @@ -70,9 +74,10 @@ public class CommandReader extends AbstractExecutionThreadService { * @param writer * The write to write results to */ - public CommandReader(Core core, Reader reader, Writer writer) { + public CommandReader(Core core, Reader reader, Writer writer, Collection failedDownloads) { this.reader = new BufferedReader(reader); - this.writer = writer; + this.writer = new DuplicateLineSuppressingWriter(writer); + this.failedDownloads = failedDownloads; /* initialize commands. */ ImmutableList.Builder commandBuilder = ImmutableList.builder(); @@ -83,6 +88,9 @@ public class CommandReader extends AbstractExecutionThreadService { commandBuilder.add(new ListConnectionsCommand(core)); commandBuilder.add(new AbortDownloadCommand(core)); commandBuilder.add(new DisconnectCommand(core)); + commandBuilder.add(new FailedDownloadsCommand(failedDownloads)); + commandBuilder.add(new RestartCommand(core, failedDownloads)); + commandBuilder.add(new ResearchCommand(core)); commands = commandBuilder.build(); } @@ -131,7 +139,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. */ } @@ -147,7 +155,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,8 +170,9 @@ public class CommandReader extends AbstractExecutionThreadService { @Subscribe public void downloadFailed(DownloadFailed downloadFailed) { Download download = downloadFailed.download(); + failedDownloads.add(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. */ }