Merge pull request #47 from nfi/cli-optional

Added option to start MSPSim without CLI
This commit is contained in:
Joakim Eriksson 2016-05-03 16:44:02 +02:00
commit 378edbb9b9
2 changed files with 21 additions and 5 deletions

View File

@ -81,9 +81,13 @@ public class StreamCommandHandler extends CommandHandler implements Runnable {
private String readLine(BufferedReader inReader2) throws IOException {
if (workaround) {
StringBuilder str = new StringBuilder();
while(true) {
while(!exit) {
if (inReader2.ready()) {
int c = inReader2.read();
if (c < 0) {
// Input stream closed
return null;
}
if (c == '\n') {
return str.toString();
}
@ -98,6 +102,7 @@ public class StreamCommandHandler extends CommandHandler implements Runnable {
}
}
}
return null;
} else {
return inReader2.readLine();
}
@ -109,12 +114,17 @@ public class StreamCommandHandler extends CommandHandler implements Runnable {
try {
out.print(prompt);
out.flush();
String line = readLine(inReader);//.readLine();
String line = readLine(inReader);
if (line == null) {
// Input stream closed
exit = true;
break;
}
// Simple execution of last called command line when not running from terminal with history support
if (((char) 27 + "[A").equals(line)) {
line = lastLine;
line = lastLine;
}
if (line != null && line.length() > 0) {
if (line.length() > 0) {
lastLine = line;
lineRead(line);
}
@ -124,6 +134,12 @@ public class StreamCommandHandler extends CommandHandler implements Runnable {
exit = true;
}
}
try {
inReader.close();
} catch (IOException e) {
err.println("Error closing command line");
e.printStackTrace(err);
}
}
}

View File

@ -217,7 +217,7 @@ public abstract class GenericNode extends Chip implements Runnable {
CommandHandler ch = registry.getComponent(CommandHandler.class, "commandHandler");
if (ch == null) {
if (ch == null && config.getPropertyAsBoolean("cli", true)) {
if (config.getPropertyAsBoolean("jconsole", false)) {
ConsoleUI console = new ConsoleUI();
PrintStream consoleStream = new PrintStream(console.getOutputStream());