This repository has been archived on 2023-11-26. You can view files and clone it, but cannot push or open issues or pull requests.
FreshCoffee/src/main/java/com/thebrokenrail/freshcoffee/dialog/server/ServerDialog.java

46 lines
1.2 KiB
Java

package com.thebrokenrail.freshcoffee.dialog.server;
import com.thebrokenrail.freshcoffee.dialog.Dialog;
import com.thebrokenrail.freshcoffee.util.Util;
import java.util.Locale;
import java.util.Scanner;
public class ServerDialog implements Dialog {
public static final Dialog INSTANCE = new ServerDialog();
private ServerDialog() {
}
@Override
public int showOptionDialog(String message, String noText, String yesText) {
noText = noText.toLowerCase(Locale.ROOT);
yesText = yesText.toLowerCase(Locale.ROOT);
Util.getLogger().info(message.replaceAll("\n", " ") + String.format(" (%1$s/%2$s) [%2$s]: ", noText, yesText));
Scanner scanner = new Scanner(System.in);
while (true) {
String line = scanner.nextLine().trim().toLowerCase(Locale.ROOT);
if (line.length() == 0) {
line = yesText;
}
if (line.equals(noText)) {
return 0;
} else if (line.equals(yesText)) {
return 1;
} else {
Util.getLogger().error("Invalid Choice: " + line);
}
}
}
@Override
public void showErrorDialog(String message) {
Util.getLogger().error(message);
}
}