Search in sources :

Example 1 with SortedMatchIterator

use of henplus.view.util.SortedMatchIterator in project henplus by neurolabs.

the class DriverCommand method complete.

@Override
public Iterator<String> complete(final CommandDispatcher disp, final String partialCommand, final String lastWord) {
    final StringTokenizer st = new StringTokenizer(partialCommand);
    final String cmd = (String) st.nextElement();
    final int argc = st.countTokens();
    // list-drivers gets no names.
    if ("list-drivers".equals(cmd)) {
        return null;
    }
    // do not complete beyond first word.
    if (argc > ("".equals(lastWord) ? 0 : 1)) {
        return null;
    }
    return new SortedMatchIterator(lastWord, _drivers);
}
Also used : StringTokenizer(java.util.StringTokenizer) SortedMatchIterator(henplus.view.util.SortedMatchIterator)

Example 2 with SortedMatchIterator

use of henplus.view.util.SortedMatchIterator in project henplus by neurolabs.

the class HelpCommand method complete.

/**
     * Returns a list of strings that are possible at this stage.
     */
@Override
public Iterator<String> complete(final CommandDispatcher disp, final String partialCommand, final String lastWord) {
    // if we already have one arguemnt and try to expand the next: no.
    final int argc = argumentCount(partialCommand);
    if (argc > 2 || argc == 2 && lastWord.length() == 0) {
        return null;
    }
    final Iterator<String> it = disp.getRegisteredCommandNames(lastWord);
    return new SortedMatchIterator(lastWord, it) {

        @Override
        protected boolean exclude(final String cmdName) {
            final Command cmd = disp.getCommandFrom(cmdName);
            return cmd.getLongDescription(cmdName) == null;
        }
    };
}
Also used : SortedMatchIterator(henplus.view.util.SortedMatchIterator) AbstractCommand(henplus.AbstractCommand) Command(henplus.Command)

Example 3 with SortedMatchIterator

use of henplus.view.util.SortedMatchIterator in project henplus by neurolabs.

the class PluginCommand method complete.

@Override
public Iterator<String> complete(final CommandDispatcher disp, final String partialCommand, final String lastWord) {
    final StringTokenizer st = new StringTokenizer(partialCommand);
    final String cmd = (String) st.nextElement();
    final int argc = st.countTokens();
    // list-plugins gets no names.
    if ("list-plugins".equals(cmd)) {
        return null;
    }
    // do not complete beyond first word.
    if (argc > ("".equals(lastWord) ? 0 : 1)) {
        return null;
    }
    return new SortedMatchIterator(lastWord, _plugins);
}
Also used : StringTokenizer(java.util.StringTokenizer) SortedMatchIterator(henplus.view.util.SortedMatchIterator)

Example 4 with SortedMatchIterator

use of henplus.view.util.SortedMatchIterator in project henplus by neurolabs.

the class SetCommand method complete.

/**
     * complete variable names.
     */
@Override
public Iterator<String> complete(final CommandDispatcher disp, final String partialCommand, final String lastWord) {
    final StringTokenizer st = new StringTokenizer(partialCommand);
    final String cmd = (String) st.nextElement();
    final int argc = st.countTokens();
    final HashSet<String> alreadyGiven = new HashSet<String>();
    if ("set-var".equals(cmd)) {
        if (argc > ("".equals(lastWord) ? 0 : 1)) {
            return null;
        }
    } else {
        /*
             * remember all variables, that have already been given on the
             * commandline and exclude from completion..
             */
        while (st.hasMoreElements()) {
            alreadyGiven.add(st.nextToken());
        }
    }
    return new SortedMatchIterator(lastWord, _variables) {

        @Override
        protected boolean exclude(final String current) {
            return alreadyGiven.contains(current);
        }
    };
}
Also used : StringTokenizer(java.util.StringTokenizer) SortedMatchIterator(henplus.view.util.SortedMatchIterator) HashSet(java.util.HashSet)

Example 5 with SortedMatchIterator

use of henplus.view.util.SortedMatchIterator in project henplus by neurolabs.

the class SetCommand method completeUserVar.

/**
     * used, if the command dispatcher notices the attempt to expand a variable. This is a partial variable name, that starts with
     * '$' or '${'.
     */
public Iterator<String> completeUserVar(final String variable) {
    if (!variable.startsWith("$")) {
        // strange, shouldn't happen.
        return null;
    }
    final boolean hasBrace = variable.startsWith("${");
    final String prefix = hasBrace ? "${" : "$";
    final String postfix = hasBrace ? "}" : "";
    final String name = variable.substring(prefix.length());
    // HenPlus.msg().println("VAR: " + variable);
    // HenPlus.msg().println("NAME: " + name);
    final SortedMatchIterator it = new SortedMatchIterator(name, _variables);
    it.setPrefix(prefix);
    it.setSuffix(postfix);
    return it;
}
Also used : SortedMatchIterator(henplus.view.util.SortedMatchIterator)

Aggregations

SortedMatchIterator (henplus.view.util.SortedMatchIterator)7 StringTokenizer (java.util.StringTokenizer)5 AbstractCommand (henplus.AbstractCommand)2 Command (henplus.Command)2 HashSet (java.util.HashSet)2 PropertyHolder (henplus.property.PropertyHolder)1