Search in sources :

Example 26 with Terminal

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();
    }
}
Also used : ConsoleCommandCompleter(org.spongepowered.server.console.ConsoleCommandCompleter) EndOfFileException(org.jline.reader.EndOfFileException) LineReader(org.jline.reader.LineReader) UserInterruptException(org.jline.reader.UserInterruptException) Terminal(org.jline.terminal.Terminal) Inject(org.spongepowered.asm.mixin.injection.Inject)

Example 27 with Terminal

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());
}
Also used : Terminal(org.jline.terminal.Terminal)

Example 28 with Terminal

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;
}
Also used : EndOfFileException(org.jline.reader.EndOfFileException) LineReader(org.jline.reader.LineReader) UserInterruptException(org.jline.reader.UserInterruptException) Terminal(org.jline.terminal.Terminal)

Example 29 with Terminal

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;
}
Also used : EndOfFileException(org.jline.reader.EndOfFileException) LineReader(org.jline.reader.LineReader) UserInterruptException(org.jline.reader.UserInterruptException) Terminal(org.jline.terminal.Terminal)

Example 30 with Terminal

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);
}
Also used : LineReader(org.jline.reader.LineReader) Terminal(org.jline.terminal.Terminal)

Aggregations

Terminal (org.jline.terminal.Terminal)39 LineReader (org.jline.reader.LineReader)14 IOException (java.io.IOException)13 InputStream (java.io.InputStream)8 EndOfFileException (org.jline.reader.EndOfFileException)8 UserInterruptException (org.jline.reader.UserInterruptException)8 ByteArrayInputStream (java.io.ByteArrayInputStream)7 Attributes (org.jline.terminal.Attributes)7 PrintStream (java.io.PrintStream)6 Path (java.nio.file.Path)6 CommandSession (org.apache.felix.service.command.CommandSession)6 OutputStream (java.io.OutputStream)5 ArrayList (java.util.ArrayList)5 InputStreamReader (java.io.InputStreamReader)4 Reader (java.io.Reader)4 ParsedLine (org.jline.reader.ParsedLine)4 BufferedReader (java.io.BufferedReader)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 File (java.io.File)3 FileInputStream (java.io.FileInputStream)3