Search in sources :

Example 1 with ConsoleCommandCompleter

use of org.spongepowered.server.console.ConsoleCommandCompleter 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)

Aggregations

EndOfFileException (org.jline.reader.EndOfFileException)1 LineReader (org.jline.reader.LineReader)1 UserInterruptException (org.jline.reader.UserInterruptException)1 Terminal (org.jline.terminal.Terminal)1 Inject (org.spongepowered.asm.mixin.injection.Inject)1 ConsoleCommandCompleter (org.spongepowered.server.console.ConsoleCommandCompleter)1