use of org.jline.reader.EndOfFileException in project LanternServer by LanternPowered.
the class ConsoleManager method readCommandTask.
/**
* This task handles the commands that are executed through the console.
*/
private void readCommandTask() {
final LineReader lineReader = TerminalConsoleAppender.getReader();
final Supplier<String> consoleReader;
if (lineReader != null) {
consoleReader = () -> {
try {
return lineReader.readLine("> ");
} catch (EndOfFileException e) {
return null;
}
};
} else {
this.logger.info("Falling back to non jline console.");
final BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
consoleReader = () -> {
try {
return reader.readLine();
} catch (IOException e) {
return null;
}
};
}
final SpongeExecutorService executor = this.scheduler.createSyncExecutor(this.pluginContainer);
try {
String command;
while (active) {
command = consoleReader.get();
if (command != null) {
command = command.trim();
if (!command.isEmpty()) {
final String runCommand = command.startsWith("/") ? command.substring(1) : command;
executor.execute(() -> this.commandManager.process(LanternConsoleSource.INSTANCE, runCommand));
}
}
}
} catch (UserInterruptException e) {
// Already set the reader to null, to avoid printing a new line
TerminalConsoleAppender.setReader(null);
// When a user interrupts the console, for example Ctrl-C
// Shutdown the server
executor.execute(() -> Lantern.getServer().shutdown());
}
}
Aggregations