14 changed files with 195 additions and 49 deletions
@ -0,0 +1,32 @@ |
|||
package internal.hw.crawler.commands; |
|||
|
|||
public class InputParser { |
|||
private InputParser() {} |
|||
|
|||
public static ParsedInput parse(String input) { |
|||
String text = input == null ? "" : input.trim(); |
|||
if (text.isEmpty()) { |
|||
return null; |
|||
} |
|||
String[] parts = text.split("\\s+"); |
|||
return new ParsedInput(parts[0].toLowerCase(), parts); |
|||
} |
|||
|
|||
public static class ParsedInput { |
|||
private final String command; |
|||
private final String[] args; |
|||
|
|||
public ParsedInput(String command, String[] args) { |
|||
this.command = command; |
|||
this.args = args; |
|||
} |
|||
|
|||
public String command() { |
|||
return command; |
|||
} |
|||
|
|||
public String[] args() { |
|||
return args; |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,31 @@ |
|||
package internal.hw.crawler.views; |
|||
|
|||
public class ProgressTracker { |
|||
private static final int BAR_WIDTH = 30; |
|||
private final CommandOutput out; |
|||
|
|||
public ProgressTracker(CommandOutput out) { |
|||
this.out = out; |
|||
} |
|||
|
|||
public void update(int done, int total) { |
|||
if (total <= 0) return; |
|||
int filled = (int) ((double) done / total * BAR_WIDTH); |
|||
StringBuilder bar = new StringBuilder("["); |
|||
for (int i = 0; i < BAR_WIDTH; i++) { |
|||
if (i < filled) { |
|||
bar.append("="); |
|||
} else if (i == filled) { |
|||
bar.append(">"); |
|||
} else { |
|||
bar.append(" "); |
|||
} |
|||
} |
|||
bar.append("] ").append(done).append("/").append(total); |
|||
out.printInline(bar.toString()); |
|||
} |
|||
|
|||
public void done() { |
|||
out.print(""); |
|||
} |
|||
} |
|||
Loading…
Reference in new issue