Files
i2p.itoopie/installer/java/src/CliInstall.java

71 lines
1.8 KiB
Java
Raw Normal View History

2004-04-10 11:55:25 +00:00
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintStream;
2004-04-08 04:41:54 +00:00
public class CliInstall extends Install {
private BufferedReader _in;
private PrintStream _out;
2004-04-10 11:55:25 +00:00
2004-04-08 04:41:54 +00:00
public CliInstall() {
2004-04-10 11:55:25 +00:00
_out = System.out;
_in = new BufferedReader(new InputStreamReader(System.in));
2004-04-08 04:41:54 +00:00
}
public void showStatus(String s) {
2004-04-10 11:55:25 +00:00
_out.println(s);
2004-04-08 04:41:54 +00:00
}
2004-04-10 11:55:25 +00:00
2004-04-08 04:41:54 +00:00
public void showOptError(String s) {
2004-04-10 11:55:25 +00:00
_out.println(s);
2004-04-08 04:41:54 +00:00
}
public void handleOptInfo(String s) {
2004-04-10 11:55:25 +00:00
_out.println(s);
2004-04-08 04:41:54 +00:00
}
public void startOptCategory(String s) {
2004-04-10 11:55:25 +00:00
_out.println("* " + s + "\n");
2004-04-08 04:41:54 +00:00
}
2004-04-10 11:55:25 +00:00
public void finishOptions() {
}
2004-04-08 04:41:54 +00:00
2004-04-10 11:55:25 +00:00
public void handleOption(int number, String question, String def, String type) {
Object value;
while (true) {
String answer;
_out.print(question + (def == null ? "" : (" [" + def + "]")) + ": ");
answer = readLine();
if ("".equals(answer) && def != null) {
answer = def;
}
if (setOption(number, answer)) break;
}
2004-04-08 04:41:54 +00:00
}
public boolean confirmOption(String question, boolean defaultYes) {
2004-04-10 11:55:25 +00:00
_out.print(question);
return readBool(defaultYes);
2004-04-08 04:41:54 +00:00
}
private String readLine() {
2004-04-10 11:55:25 +00:00
try {
return _in.readLine().trim();
} catch (IOException ex) {
ex.printStackTrace();
System.exit(1);
return null;
}
2004-04-08 04:41:54 +00:00
}
2004-04-10 11:55:25 +00:00
2004-04-08 04:41:54 +00:00
private boolean readBool(boolean defaultYes) {
2004-04-10 11:55:25 +00:00
String str = readLine().toLowerCase();
if ("".equals(str)) return defaultYes;
return "yes".equals(str) || "y".equals(str) || "true".equals(str) || "ok".equals(str) || "sure".equals(str)
|| "whatever".equals(str);
2004-04-08 04:41:54 +00:00
}
2004-04-10 11:55:25 +00:00
}