*
* @return true if the event should commit the characters in the
* input (line editing) buffer to the Reader's character stream.
*/
private boolean processEvent() throws IOException {
KeyboardEvent event = keyboardHandler.getEvent();
if (!event.isConsumed()) {
KeyboardReaderAction action = bindings.getKeyboardEventAction(event);
boolean breakChar = false;
boolean consume = true;
switch (action) {
case KR_DELETE_BEFORE:
// Delete character before cursor
if (currentLine.backspace()) {
refreshCurrentLine();
}
break;
case KR_ENTER:
// Append event character to the line and commit.
currentLine.moveEnd();
refreshCurrentLine();
out.write('\n');
currentLine.appendChar(event.getKeyChar());
breakChar = true;
historyIndex = -1;
break;
case KR_COMPLETE:
// Perform completion
if (completer != null) {
if (currentLine.complete(completer)) {
currentLine.start(true);
}
out.write(currentPrompt);
refreshCurrentLine();
}
break;
case KR_HELP:
// Request incremental help
if (completer != null) {
if (currentLine.help(completer)) {
currentLine.start(true);
}
out.write(currentPrompt);
refreshCurrentLine();
}
break;
case KR_SOFT_EOF:
// Set soft EOF status and commit
currentLine.moveEnd();
refreshCurrentLine();
out.write('\n');
eof = true;
breakChar = true;
break;
case KR_KILL_LINE:
// Kill the current input line (and clear the screen)
this.console.clear();
this.console.setCursor(0, 0);
out.write(currentPrompt);
currentLine.start();
refreshCurrentLine();
break;
case KR_INSERT:
// Insert event's character
currentLine.appendChar(event.getKeyChar());
refreshCurrentLine();
historyIndex = -1;
break;
case KR_HISTORY_UP:
// Previous history item
if (completer != null) {
if (historyIndex == -1) {
historyIndex = completer.getInputHistory().size();
savedCurrentLine = currentLine.getContent();
}
historyIndex--;
updateCurrentLine();
}
break;
case KR_HISTORY_DOWN:
// Next history item
if (completer != null) {
if (historyIndex == -1) {
savedCurrentLine = currentLine.getContent();
}
if (historyIndex == completer.getInputHistory().size() - 1) {
historyIndex = -2;
}
historyIndex++;
updateCurrentLine();
}
break;
case KR_CURSOR_LEFT:
// Move the cursor left
if (currentLine.moveLeft()) {
refreshCurrentLine();
}
break;
case KR_CURSOR_RIGHT:
// Move the cursor right
if (currentLine.moveRight()) {
refreshCurrentLine();
}
break;
case KR_CURSOR_TO_START:
// Move the cursor to the start of the line
currentLine.moveBegin();
refreshCurrentLine();
break;
case KR_CURSOR_TO_END:
// Move the cursor to the end of the line
currentLine.moveEnd();
refreshCurrentLine();
break;
case KR_DELETE_AFTER:
// Delete the character after the cursor
currentLine.delete();
refreshCurrentLine();
break;
case KR_CONSUME:
// Comsume (and ignore) the event
break;
case KR_IGNORE:
// Leave the event unconsumed.
consume = false;
break;
}
if (consume) {
event.consume();
}
return breakChar;
} else {
return false;
}