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;
}
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();
}
}
}
Aggregations