org.aesh.readline.action.KeyAction Java Examples

The following examples show how to use org.aesh.readline.action.KeyAction. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: EditMode.java    From aesh-readline with Apache License 2.0 6 votes vote down vote up
default KeyAction createKeyEvent(int[] input) {
    Key key = Key.getKey(input);
    if(key != null)
        return key;
    else {
        return new KeyAction() {
            private int[] key = input;

            @Override
            public int getCodePointAt(int index) throws IndexOutOfBoundsException {
                return key[index];
            }

            @Override
            public int length() {
                return key.length;
            }

            @Override
            public String name() {
                return Arrays.toString(key);
            }
        };
    }
}
 
Example #2
Source File: Vi.java    From aesh-readline with Apache License 2.0 6 votes vote down vote up
private ActionStatus getActionStatus(KeyAction event) {
    if(event instanceof Key) {
        ActionStatus actionStatus = actions.get(event);
        if(actionStatus != null)
            return actionStatus;
        else {
            ActionStatusGroup group = actionGroups.get(event);
            if(group != null)
                return group.getByCurrentStatus(status);

            group = keyEventActionGroups.get(event);
            if(group != null)
                return group.getByCurrentStatus(status);
        }
        return null;
    }
    else {
        return parseKeyEventActions(event);
    }
}
 
Example #3
Source File: Complete.java    From aesh-readline with Apache License 2.0 5 votes vote down vote up
@Override
public void input(Action action, KeyAction key) {
    if(askForCompletion) {
        if(Key.isPrintable(key.buffer())) {
            if(Key.y.equalTo(key.buffer().array())) {
                this.key = Key.y;
            }
            if(Key.n.equalTo(key.buffer().array())) {
                this.key = Key.n;
            }
        }
    }
}
 
Example #4
Source File: UpdateCommand.java    From galleon with Apache License 2.0 5 votes vote down vote up
@Override
protected void doRunCommand(PmCommandInvocation session, Map<String, String> options) throws CommandExecutionException {
    try {
        ProvisioningManager mgr = getManager(session);
        Updates updates = CheckUpdatesCommand.getUpdatesTable(mgr, session, allDependencies(), getFP());
        if (updates.plan.isEmpty()) {
            session.println(UP_TO_DATE);
        } else {
            session.println(UPDATES_AVAILABLE);
            session.println(updates.t.build());
            if (!noConfirm()) {
                try {
                    Key k = null;
                    while (k == null || (!Key.y.equals(k) && !Key.n.equals(k))) {
                        session.print("Proceed with latest updates [y/n]?");
                        KeyAction a = session.input();
                        k = Key.findStartKey(a.buffer().array());
                    }
                    if (Key.n.equals(k)) {
                        return;
                    }
                } finally {
                    session.println("");
                }
            }
            mgr.apply(updates.plan, options);
        }
    } catch (ProvisioningException | IOException ex) {
        throw new CommandExecutionException(session.getPmSession(),
                CliErrors.updateFailed(), ex);
    } catch (InterruptedException ignored) {
        // Just exit the command smoothly
    }
}
 
Example #5
Source File: Readline.java    From aesh-readline with Apache License 2.0 5 votes vote down vote up
/**
 * Parse the event given
 * @param event event
 */
private void parse(KeyAction event) {
    Action action = editMode.parse(event);
    if (action != null) {
        synchronized (Readline.this) {
            paused = true;
        }
        action.accept(this);
        editMode.setPrevKey(event);
        if(this.returnValue() != null) {
            conn.stdoutHandler().accept(Config.CR);
            finish(this.returnValue());
        }
        else {
            synchronized (Readline.this) {
                paused = false;
            }
            //some actions might call finish
            if(inputProcessor != null)
                processInput();
        }
    }
    else {
        if(Key.isPrintable(event.buffer()) && notInCommandNode())
            this.buffer().writeChar((char) event.buffer().array()[0]);
    }
}
 
Example #6
Source File: Vi.java    From aesh-readline with Apache License 2.0 5 votes vote down vote up
@Override
public Action parse(KeyAction event) {
    //are we already searching, it need to be processed by search action
    if(currentAction != null) {
        if(currentAction.keepFocus()) {
            currentAction.input(getAction(event), event);
            return currentAction;
        }
        else
            currentAction = null;
    }

    return getAction(event);
}
 
Example #7
Source File: Emacs.java    From aesh-readline with Apache License 2.0 5 votes vote down vote up
private Action getAction(KeyAction event) {
    Action action;
    if(event instanceof Key && actions.containsKey(event)) {
        action = actions.get(event);
    }
    else {
        action  = parseKeyEventActions(event);
    }
    if(action != null && action instanceof ActionEvent) {
        currentAction = (ActionEvent) action;
        currentAction.input(action, event);
    }
    return action;
}
 
Example #8
Source File: Vi.java    From aesh-readline with Apache License 2.0 5 votes vote down vote up
private ActionStatus parseKeyEventActions(KeyAction event) {
    for(KeyAction key : keyEventActions.keySet()) {
        boolean isEquals = true;
        if(key.length() == event.length()) {
            for(int i=0; i<key.length() && isEquals; i++)
                if(key.getCodePointAt(i) != event.getCodePointAt(i))
                    isEquals = false;

            if(isEquals)
                return keyEventActions.get(key);
        }
    }
    return null;
}
 
Example #9
Source File: Emacs.java    From aesh-readline with Apache License 2.0 5 votes vote down vote up
@Override
public Action parse(KeyAction event) {
    //are we already searching, it need to be processed by search action
    if(currentAction != null) {
        if(currentAction.keepFocus()) {
            currentAction.input(getAction(event), event);
            return currentAction;
        }
        else
            currentAction = null;
    }

    return getAction(event);
}
 
Example #10
Source File: Emacs.java    From aesh-readline with Apache License 2.0 4 votes vote down vote up
@Override
public void setPrevKey(KeyAction event) {
    prevKey = event;
}
 
Example #11
Source File: CLICommandInvocationImpl.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
@Override
public KeyAction input() throws InterruptedException {
    return shell.read();
}
 
Example #12
Source File: SearchHistory.java    From aesh-readline with Apache License 2.0 4 votes vote down vote up
@Override
public void input(Action action, KeyAction key) {
     if(action == null && Key.isPrintable(key.buffer())) {
         if(searchArgument == null)
             searchArgument = new IntArrayBuilder(1);
         status = defaultAction;
         searchArgument.append(key.buffer().array()[0]);
     }
     else if(action instanceof Interrupt) {
         status = Status.SEARCH_INTERRUPT;
     }
     else if(action instanceof Enter) {
         status = Status.SEARCH_END;
     }
     else if(action instanceof ReverseSearchHistory) {
         status = Status.SEARCH_PREV;
     }
     else if(action instanceof ForwardSearchHistory) {
         status = Status.SEARCH_NEXT;
     }
     else if(action instanceof DeletePrevChar) {
         status = Status.SEARCH_DELETE;
     }
     else if(action instanceof PrevHistory)
         status = Status.SEARCH_MOVE_PREV;
     else if(action instanceof NextHistory)
         status = Status.SEARCH_MOVE_NEXT;
     else if(action instanceof ForwardChar) {
         status = Status.SEARCH_MOVE_RIGHT;
     }
     else if(action instanceof BackwardChar)
         status = Status.SEARCH_MOVE_LEFT;
     else {
         if(key == Key.ESC) {
             status = Status.SEARCH_EXIT;
         }
         else if(key == Key.CTRL_D) {
             status = Status.SEARCH_EXIT;
         }
         if(Key.isPrintable(key.buffer())) {
             if(searchArgument == null)
                 searchArgument = new IntArrayBuilder(1);
             status = defaultAction;
             searchArgument.append(key.buffer().array()[0]);
         }
     }
}
 
Example #13
Source File: Emacs.java    From aesh-readline with Apache License 2.0 4 votes vote down vote up
private Action parseKeyEventActions(KeyAction event) {
    for(KeyAction key : keyEventActions.keySet()) {
        boolean isEquals = true;
        if(key.length() == event.length()) {
            for(int i=0; i<key.length() && isEquals; i++)
                if(key.getCodePointAt(i) != event.getCodePointAt(i))
                    isEquals = false;

            if(isEquals)
                return keyEventActions.get(key);
        }
    }
    //if we have ctrlX from the previous input
    if(ctrlX) {
        if (event.length() == 1) {
            ctrlX = false;
            KeyAction customCtrlX = new KeyAction() {
                @Override
                public int getCodePointAt(int index) throws IndexOutOfBoundsException {
                    if (index == 0)
                        return Key.CTRL_X.getFirstValue();
                    else
                        return event.getCodePointAt(0);
                }

                @Override
                public int length() {
                    return 2;
                }

                @Override
                public String name() {
                    return "Ctrl-x+" + event.name();
                }
            };
            return parseKeyEventActions(customCtrlX);
        }
        else {
            ctrlX = false;
            return null;
        }
    }

    if(event.getCodePointAt(0) == Key.CTRL_X.getFirstValue()) {
        ctrlX = true;
    }

    return null;
}
 
Example #14
Source File: OutputPmCommandInvocation.java    From galleon with Apache License 2.0 4 votes vote down vote up
@Override
public KeyAction input() throws InterruptedException {
    return delegate.input();

}
 
Example #15
Source File: Emacs.java    From aesh-readline with Apache License 2.0 4 votes vote down vote up
@Override
public KeyAction prevKey() {
    return prevKey;
}
 
Example #16
Source File: Vi.java    From aesh-readline with Apache License 2.0 4 votes vote down vote up
private Action getAction(KeyAction event) {
    ActionStatus newStatus = getActionStatus(event);
    if(newStatus == null)
        return null;
    else {
        if(newStatus.getCurrentStatus() == status) {
            if(newStatus.getAction() instanceof ActionEvent) {
                currentAction = (ActionEvent) newStatus.getAction();
                currentAction.input(newStatus.getAction(), event);
            }
            else {
                if(newStatus.nextStatus == Status.REPEAT) {
                    return previousAction;
                }
                else {
                    if(status == Status.DELETE ||
                            newStatus.actionStatus == Status.DELETE ||
                            newStatus.actionStatus == Status.CHANGE)
                        previousAction = newStatus.getAction();
                    status = newStatus.nextStatus;
                }
            }
            return newStatus.getAction();
        }
        else
            return null;
     }

    /*
    if(event instanceof Key) {
        parseKeyEvent((Key) event);
    }

    if(actions.containsKey(event)) {
        ActionStatus actionStatus =  actions.get(event);
        if(actionStatus.getAction() instanceof ActionEvent) {
            currentAction = (ActionEvent) actionStatus.getAction();
            currentAction.input(actionStatus.getAction(), event);
        }
        return actionStatus.getAction();
    }
    else {
        return null;
    }
    */
}
 
Example #17
Source File: Vi.java    From aesh-readline with Apache License 2.0 4 votes vote down vote up
@Override
public void setPrevKey(KeyAction event) {
    prevKey = event;
}
 
Example #18
Source File: Vi.java    From aesh-readline with Apache License 2.0 4 votes vote down vote up
@Override
public KeyAction prevKey() {
    return prevKey;
}
 
Example #19
Source File: CliShellPmCommandInvocation.java    From galleon with Apache License 2.0 4 votes vote down vote up
@Override
public KeyAction input() throws InterruptedException {
    return shell.read();
}
 
Example #20
Source File: InteractivePmCommandInvocation.java    From galleon with Apache License 2.0 4 votes vote down vote up
@Override
public KeyAction input() throws InterruptedException {
    return delegate.input();

}
 
Example #21
Source File: EditMode.java    From aesh-readline with Apache License 2.0 votes vote down vote up
KeyAction[] keys(); 
Example #22
Source File: EditMode.java    From aesh-readline with Apache License 2.0 votes vote down vote up
Action parse(KeyAction event); 
Example #23
Source File: EditMode.java    From aesh-readline with Apache License 2.0 votes vote down vote up
KeyAction prevKey(); 
Example #24
Source File: EditMode.java    From aesh-readline with Apache License 2.0 votes vote down vote up
void setPrevKey(KeyAction event);