Search in sources :

Example 1 with Terminal

use of jline.Terminal 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 2 with Terminal

use of jline.Terminal in project GeoGig by boundlessgeo.

the class GeogigConsole method run.

private void run(final InputStream in, final OutputStream out) throws IOException {
    final Terminal terminal;
    if (interactive) {
        terminal = null;
    /* let jline select an appropriate one */
    } else {
        // no colors in output
        terminal = new UnsupportedTerminal();
    }
    ConsoleReader consoleReader = new ConsoleReader(in, out, terminal);
    consoleReader.setAutoprintThreshold(20);
    consoleReader.setPaginationEnabled(interactive);
    consoleReader.setHistoryEnabled(interactive);
    // needed for CTRL+C not to let the console broken
    consoleReader.getTerminal().setEchoEnabled(interactive);
    final GeogigCLI cli = new GeogigCLI(consoleReader);
    if (interactive) {
        addCommandCompleter(consoleReader, cli);
    } else {
        // no progress percent in output
        cli.disableProgressListener();
    }
    GeogigCLI.addShutdownHook(cli);
    setPrompt(cli);
    cli.close();
    try {
        runInternal(cli);
    } finally {
        try {
            cli.close();
        } finally {
            try {
                if (terminal != null) {
                    terminal.restore();
                }
                consoleReader.shutdown();
            } catch (Exception e) {
                throw Throwables.propagate(e);
            }
        }
    }
}
Also used : ConsoleReader(jline.console.ConsoleReader) UnsupportedTerminal(jline.UnsupportedTerminal) Terminal(jline.Terminal) UnsupportedTerminal(jline.UnsupportedTerminal) IOException(java.io.IOException)

Aggregations

Terminal (jline.Terminal)2 UnsupportedTerminal (jline.UnsupportedTerminal)2 ConsoleReader (jline.console.ConsoleReader)2 FileInputStream (java.io.FileInputStream)1 IOException (java.io.IOException)1