You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
54 lines
1.3 KiB
54 lines
1.3 KiB
package internal.hw.crawler.views;
|
|
|
|
import java.util.NoSuchElementException;
|
|
import java.util.Scanner;
|
|
|
|
public class ConsoleView implements CommandOutput {
|
|
private static final String ANSI_RESET = "\u001B[0m";
|
|
private static final String ANSI_GREEN = "\u001B[32m";
|
|
private static final String ANSI_RED = "\u001B[31m";
|
|
private static final String ANSI_BLUE = "\u001B[34m";
|
|
|
|
private final Scanner scanner = new Scanner(System.in);
|
|
|
|
public String readLine() {
|
|
System.out.print("> ");
|
|
try {
|
|
return scanner.nextLine();
|
|
} catch (NoSuchElementException | IllegalStateException e) {
|
|
return null;
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public void print(String msg) {
|
|
System.out.println(msg);
|
|
}
|
|
|
|
public void printSuccess(String msg) {
|
|
System.out.println(ANSI_GREEN + msg + ANSI_RESET);
|
|
}
|
|
|
|
public void printError(String msg) {
|
|
System.out.println(ANSI_RED + msg + ANSI_RESET);
|
|
}
|
|
|
|
public void printInfo(String msg) {
|
|
System.out.println(ANSI_BLUE + msg + ANSI_RESET);
|
|
}
|
|
|
|
@Override
|
|
public void success(String msg) {
|
|
printSuccess(msg);
|
|
}
|
|
|
|
@Override
|
|
public void error(String msg) {
|
|
printError(msg);
|
|
}
|
|
|
|
@Override
|
|
public void info(String msg) {
|
|
printInfo(msg);
|
|
}
|
|
}
|
|
|