use of jline.console.KeyMap 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