use of org.jline.terminal.Terminal in project SpongeVanilla by SpongePowered.
the class MixinConsoleHandler method onRun.
@Inject(method = "run", at = @At("HEAD"), cancellable = true, remap = false)
private void onRun(CallbackInfo ci) {
final Terminal terminal = TerminalConsoleAppender.getTerminal();
if (terminal != null) {
LineReader reader = LineReaderBuilder.builder().appName("SpongeVanilla").terminal(terminal).completer(new ConsoleCommandCompleter(this.server)).build();
reader.unsetOpt(LineReader.Option.INSERT_TAB);
TerminalConsoleAppender.setReader(reader);
try {
String line;
while (!this.server.isServerStopped() && this.server.isServerRunning()) {
try {
line = reader.readLine("> ");
} catch (EndOfFileException e) {
// Continue reading after EOT
continue;
}
if (line == null) {
break;
}
line = line.trim();
if (!line.isEmpty()) {
this.server.addPendingCommand(line, this.server);
}
}
} catch (UserInterruptException e) {
this.server.initiateShutdown();
} finally {
TerminalConsoleAppender.setReader(null);
}
ci.cancel();
}
}
use of org.jline.terminal.Terminal in project jPOS by jpos.
the class ENV method exec.
public void exec(CLIContext cli, String[] args) throws Exception {
Terminal term = cli.getReader().getTerminal();
cli.println("TERM=" + term.getClass().getSimpleName() + "/" + term.getType());
cli.println(Environment.getEnvironment().toString());
}
use of org.jline.terminal.Terminal in project Payara by payara.
the class AsadminSecurityUtil method promptForPassword.
/**
* If we fail to open the client database using the default password
* (changeit) or the password found in "javax.net.ssl.trustStorePassword"
* system property, then the fallback behavior is to prompt the user for
* the password by calling this method.
* @return the password to the client side truststore
*/
private char[] promptForPassword() {
LineReader lineReader = null;
try {
char mask = 0;
Terminal terminal = TerminalBuilder.builder().system(true).build();
lineReader = LineReaderBuilder.builder().terminal(terminal).build();
String line = lineReader.readLine(strmgr.get("certificateDbPrompt"), mask);
return line.toCharArray();
} catch (IOException ioe) {
logger.log(Level.WARNING, "Error reading input", ioe);
} catch (UserInterruptException | EndOfFileException e) {
// Ignore
} finally {
if (lineReader != null && lineReader.getTerminal() != null) {
try {
lineReader.getTerminal().close();
} catch (IOException ioe) {
logger.log(Level.WARNING, "Error closing terminal", ioe);
}
}
}
return null;
}
use of org.jline.terminal.Terminal in project MinecraftForge by MinecraftForge.
the class TerminalHandler method handleCommands.
public static boolean handleCommands(DedicatedServer server) {
final Terminal terminal = TerminalConsoleAppender.getTerminal();
if (terminal == null)
return false;
LineReader reader = LineReaderBuilder.builder().appName("Forge").terminal(terminal).completer(new ConsoleCommandCompleter(server)).build();
reader.setOpt(LineReader.Option.DISABLE_EVENT_EXPANSION);
reader.unsetOpt(LineReader.Option.INSERT_TAB);
TerminalConsoleAppender.setReader(reader);
try {
String line;
while (!server.isStopped() && server.isRunning()) {
try {
line = reader.readLine("> ");
} catch (EndOfFileException ignored) {
// Continue reading after EOT
continue;
}
if (line == null)
break;
line = line.trim();
if (!line.isEmpty()) {
server.handleConsoleInput(line, server.createCommandSourceStack());
}
}
} catch (UserInterruptException e) {
server.halt(true);
} finally {
TerminalConsoleAppender.setReader(null);
}
return true;
}
use of org.jline.terminal.Terminal in project LanternServer by LanternPowered.
the class ConsoleManager method start.
public void start() {
final Terminal terminal = TerminalConsoleAppender.getTerminal();
if (terminal != null) {
final LineReader reader = LineReaderBuilder.builder().appName(this.pluginContainer.getName()).terminal(terminal).completer(new ConsoleCommandCompleter()).build();
reader.unsetOpt(Option.INSERT_TAB);
reader.setVariable(LineReader.HISTORY_FILE, this.consoleHistoryFile);
TerminalConsoleAppender.setReader(reader);
}
active = true;
final Thread thread = new Thread(this::readCommandTask, "console");
thread.setDaemon(true);
thread.start();
this.scheduler.createAsyncExecutor(this.pluginContainer).scheduleAtFixedRate(this::saveHistory, 120, 120, TimeUnit.SECONDS);
}
Aggregations