Search in sources :

Example 1 with CursorBuffer

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

the class CandidateListCompletionHandler method complete.

public boolean complete(ConsoleReader reader, @SuppressWarnings("rawtypes") List<CharSequence> candidates, int pos) throws IOException {
    CursorBuffer buf = reader.getCursorBuffer();
    // if there is only one completion, then fill in the buffer
    if (candidates.size() == 1) {
        String value = candidates.get(0).toString();
        // fail if the only candidate is the same as the current buffer
        if (value.equals(buf.toString())) {
            return false;
        }
        jline.console.completer.CandidateListCompletionHandler.setBuffer(reader, value, pos);
        return true;
    }
    if (candidates.size() > 1) {
        String value = getUnambiguousCompletions(candidates);
        jline.console.completer.CandidateListCompletionHandler.setBuffer(reader, value, pos);
    }
    if (eagerNewlines) {
        reader.println();
    }
    jline.console.completer.CandidateListCompletionHandler.printCandidates(reader, candidates);
    // redraw the current console buffer
    reader.drawLine();
    return true;
}
Also used : CursorBuffer(jline.console.CursorBuffer)

Example 2 with CursorBuffer

use of jline.console.CursorBuffer in project voltdb by VoltDB.

the class SQLCommand method interactWithTheUser.

// The main loop for interactive mode.
public static void interactWithTheUser() throws Exception {
    final SQLConsoleReader interactiveReader = new SQLConsoleReader(new FileInputStream(FileDescriptor.in), System.out);
    interactiveReader.setBellEnabled(false);
    FileHistory historyFile = null;
    try {
        // Maintain persistent history in ~/.sqlcmd_history.
        historyFile = new FileHistory(new File(System.getProperty("user.home"), ".sqlcmd_history"));
        interactiveReader.setHistory(historyFile);
        // Make Ctrl-D (EOF) exit if on an empty line, otherwise delete the next character.
        KeyMap keyMap = interactiveReader.getKeys();
        keyMap.bind(new Character(KeyMap.CTRL_D).toString(), new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                CursorBuffer cursorBuffer = interactiveReader.getCursorBuffer();
                if (cursorBuffer.length() == 0) {
                    // tells caller to stop (basically a goto)
                    throw new SQLCmdEarlyExitException();
                } else {
                    try {
                        interactiveReader.delete();
                    } catch (IOException e1) {
                    }
                }
            }
        });
        getInteractiveQueries(interactiveReader);
    } finally {
        // Flush input history to a file.
        if (historyFile != null) {
            try {
                historyFile.flush();
            } catch (IOException e) {
                System.err.printf("* Unable to write history to \"%s\" *\n", historyFile.getFile().getPath());
                if (m_debug) {
                    e.printStackTrace();
                }
            }
        }
        // Clean up jline2 resources.
        if (interactiveReader != null) {
            interactiveReader.shutdown();
        }
    }
}
Also used : ActionListener(java.awt.event.ActionListener) ActionEvent(java.awt.event.ActionEvent) CursorBuffer(jline.console.CursorBuffer) IOException(java.io.IOException) File(java.io.File) FileInputStream(java.io.FileInputStream) FileHistory(jline.console.history.FileHistory) KeyMap(jline.console.KeyMap)

Aggregations

CursorBuffer (jline.console.CursorBuffer)2 ActionEvent (java.awt.event.ActionEvent)1 ActionListener (java.awt.event.ActionListener)1 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 IOException (java.io.IOException)1 KeyMap (jline.console.KeyMap)1 FileHistory (jline.console.history.FileHistory)1