Search in sources :

Example 46 with ConsoleReader

use of jline.console.ConsoleReader in project grails-core by grails.

the class GrailsConsole method resetCompleters.

public void resetCompleters() {
    final ConsoleReader reader = getReader();
    if (reader != null) {
        Collection<Completer> completers = reader.getCompleters();
        for (Completer completer : completers) {
            reader.removeCompleter(completer);
        }
        // for some unknown reason / bug in JLine you have to iterate over twice to clear the completers (WTF)
        completers = reader.getCompleters();
        for (Completer completer : completers) {
            reader.removeCompleter(completer);
        }
    }
}
Also used : ConsoleReader(jline.console.ConsoleReader) Completer(jline.console.completer.Completer)

Example 47 with ConsoleReader

use of jline.console.ConsoleReader in project MinecraftForge by MinecraftForge.

the class TerminalConsoleAppender method start.

@Override
public void start() {
    // Initialize the reader if that hasn't happened yet
    if (!initialized && reader == null) {
        initialized = true;
        if (ENABLE_JLINE) {
            final boolean hasConsole = System.console() != null;
            if (hasConsole) {
                try {
                    AnsiConsole.systemInstall();
                    reader = new ConsoleReader();
                    reader.setExpandEvents(false);
                } catch (Exception e) {
                    LOGGER.warn("Failed to initialize terminal. Falling back to default.", e);
                }
            }
            if (reader == null) {
                if (hasConsole || System.getProperty("java.class.path").contains("idea_rt.jar")) {
                    // Disable advanced jline features
                    TerminalFactory.configure(OFF);
                    TerminalFactory.reset();
                    try {
                        reader = new ConsoleReader();
                        reader.setExpandEvents(false);
                    } catch (Exception e) {
                        LOGGER.warn("Failed to initialize fallback terminal. Falling back to standard output console.", e);
                    }
                } else {
                    LOGGER.warn("Disabling terminal, you're running in an unsupported environment.");
                }
            }
        }
    }
    super.start();
}
Also used : ConsoleReader(jline.console.ConsoleReader) IOException(java.io.IOException)

Example 48 with ConsoleReader

use of jline.console.ConsoleReader in project MinecraftForge by MinecraftForge.

the class TerminalHandler method handleCommands.

public static boolean handleCommands(DedicatedServer server) {
    final ConsoleReader reader = TerminalConsoleAppender.getReader();
    if (reader != null) {
        TerminalConsoleAppender.setFormatter(new ConsoleFormatter());
        reader.addCompleter(new ConsoleCommandCompleter(server));
        String line;
        while (!server.isServerStopped() && server.isServerRunning()) {
            try {
                line = reader.readLine("> ");
                if (line == null) {
                    break;
                }
                line = line.trim();
                if (!line.isEmpty()) {
                    server.addPendingCommand(line, server);
                }
            } catch (IOException e) {
                logger.error("Exception handling console input", e);
            }
        }
        return true;
    } else {
        TerminalConsoleAppender.setFormatter(new Function<String, String>() {

            @Override
            public String apply(String text) {
                return TextFormatting.getTextWithoutFormattingCodes(text);
            }
        });
        return false;
    }
}
Also used : ConsoleReader(jline.console.ConsoleReader) IOException(java.io.IOException)

Example 49 with ConsoleReader

use of jline.console.ConsoleReader in project es6draft by anba.

the class JLineConsole method newConsoleReader.

private static ConsoleReader newConsoleReader(String programName) throws IOException {
    final boolean isWindows = isWindows();
    final String type = System.getProperty(TerminalFactory.JLINE_TERMINAL);
    if (isWindows && type == null) {
        TerminalFactory.registerFlavor(TerminalFactory.Flavor.WINDOWS, UnsupportedTerminal.class);
    } else if (isWindows && type.equalsIgnoreCase(TerminalFactory.UNIX)) {
        TerminalFactory.registerFlavor(TerminalFactory.Flavor.UNIX, CygwinTerminal.class);
    }
    FileInputStream in = new FileInputStream(FileDescriptor.in);
    Terminal terminal = TerminalFactory.get();
    ConsoleReader consoleReader = new ConsoleReader(programName, in, System.out, terminal, getDefaultEncoding());
    consoleReader.setExpandEvents(false);
    return consoleReader;
}
Also used : ConsoleReader(jline.console.ConsoleReader) Terminal(jline.Terminal) UnsupportedTerminal(jline.UnsupportedTerminal) FileInputStream(java.io.FileInputStream)

Example 50 with ConsoleReader

use of jline.console.ConsoleReader in project geode by apache.

the class ScriptExecutionDetails method createConsoleReader.

@Override
protected ConsoleReader createConsoleReader() {
    ConsoleReader consoleReader = super.createConsoleReader();
    consoleReader.setHistory(gfshHistory);
    terminal = consoleReader.getTerminal();
    return consoleReader;
}
Also used : ConsoleReader(jline.console.ConsoleReader)

Aggregations

ConsoleReader (jline.console.ConsoleReader)97 UnsupportedTerminal (jline.UnsupportedTerminal)44 GeogigCLI (org.locationtech.geogig.cli.GeogigCLI)42 GeoGIG (org.locationtech.geogig.api.GeoGIG)22 IOException (java.io.IOException)19 Before (org.junit.Before)19 Test (org.junit.Test)17 File (java.io.File)12 MockitoException (org.mockito.exceptions.base.MockitoException)12 CommandFailedException (org.locationtech.geogig.cli.CommandFailedException)11 ObjectId (org.locationtech.geogig.api.ObjectId)9 TestPlatform (org.locationtech.geogig.api.TestPlatform)8 CommitOp (org.locationtech.geogig.api.porcelain.CommitOp)8 Ref (org.locationtech.geogig.api.Ref)7 CLITestContextBuilder (org.locationtech.geogig.cli.test.functional.general.CLITestContextBuilder)7 Ansi (org.fusesource.jansi.Ansi)6 NodeRef (org.locationtech.geogig.api.NodeRef)6 RevCommit (org.locationtech.geogig.api.RevCommit)6 FileInputStream (java.io.FileInputStream)4 RevObject (org.locationtech.geogig.api.RevObject)4