}
@Override
public String parseOperation(CommandOperation commandOperation) throws IOException {
Operation operation = consoleBuffer.getEditMode().parseInput(commandOperation.getInputKey(),
consoleBuffer.getBuffer().getLine());
if(commandOperation.getInputKey() != Key.UNKNOWN)
operation.setInput(commandOperation.getInputKey().getKeyValues());
else
operation.setInput(new int[]{ commandOperation.getInput()[commandOperation.getPosition()]});
Action action = operation.getAction();
if (action == Action.EDIT) {
consoleBuffer.writeChars(operation.getInput());
}
//make sure that every action except delete is ignored when masking is enabled
else if(consoleBuffer.getBuffer().isMasking()) {
if(action == Action.DELETE) {
if(consoleBuffer.getBuffer().getPrompt().getMask() == 0)
deleteWithMaskEnabled();
else
consoleBuffer.performAction(EditActionManager.parseAction(operation, consoleBuffer.getBuffer().getCursor(),
consoleBuffer.getBuffer().length(), consoleBuffer.getEditMode().getMode()));
}
}
// For search movement is used a bit differently.
// It only triggers what kind of search action thats performed
else if(action == Action.SEARCH && !searchDisabled) {
if(search == null)
search = new Search(operation, operation.getInput()[0]);
else {
search.setOperation(operation);
search.setInput(operation.getInput()[0]);
}
doSearch(search);
if(search.isFinished())
return search.getResult();
}
else if(action == Action.MOVE || action == Action.DELETE ||
action == Action.CHANGE || action == Action.YANK) {
consoleBuffer.performAction(EditActionManager.parseAction(operation, consoleBuffer.getBuffer().getCursor(),
consoleBuffer.getBuffer().length(), consoleBuffer.getEditMode().getMode()));
}
else if(action == Action.ABORT) {
}
else if(action == Action.CASE) {
//capitalize word
if(operation.getMovement() == Movement.BEGINNING) {
consoleBuffer.capitalizeWord();
}
//upper case word
else if(operation.getMovement() == Movement.NEXT) {
consoleBuffer.upperCaseWord();
}
//lower case word
else if(operation.getMovement() == Movement.PREV) {
consoleBuffer.lowerCaseWord();
}
//change case of the current char
else {
consoleBuffer.addActionToUndoStack();
consoleBuffer.changeCase();
}
}
else if(action == Action.COMPLETE) {
if(operation.getMovement() == Movement.NEXT)
complete();
else {
if(completionHandler != null) {
completionHandler.setAskDisplayCompletion(false);
consoleBuffer.getUndoManager().clear();
consoleBuffer.out().print(Config.getLineSeparator());
clearBufferAndDisplayPrompt();
}
}
}
else if(action == Action.EXIT || action == Action.EOF ||
action == Action.INTERRUPT || action == Action.IGNOREEOF) {
if(interruptHook != null) {
interruptHook.handleInterrupt(action);
}
}
else if(action == Action.HISTORY && !historyDisabled) {
if(operation.getMovement() == Movement.NEXT)
getHistoryElement(true);
else if(operation.getMovement() == Movement.PREV)
getHistoryElement(false);
}
else if(action == Action.UNDO) {
undo();
}
else if(action == Action.PASTE_FROM_CLIPBOARD) {
consoleBuffer.addActionToUndoStack();
//paste();
}
else if(action == Action.PASTE) {
if(operation.getMovement() == Movement.NEXT)
consoleBuffer.paste(0, true);
else
consoleBuffer.paste(0, false);
}
else if(action == Action.CHANGE_EDITMODE) {
changeEditMode(operation.getMovement());
}
else if(action == Action.CLEAR) {
consoleBuffer.clear(true);
}
else if(action == Action.REPLACE) {
consoleBuffer.replace(operation.getInput()[0]);
}
else if(action == Action.NO_ACTION) {
//atm do nothing
}