Search in sources :

Example 6 with Candidate

use of org.jline.reader.Candidate in project jPOS by jpos.

the class CLIPrefixedClassNameCompleter method toString.

public String toString() {
    StringBuilder sb = new StringBuilder("CLIPrefixedClassNameCompletor[");
    sb.append(hashCode());
    for (Candidate c : candidates) {
        sb.append(System.getProperty("line.separator"));
        sb.append(" ");
        sb.append(c.value());
    }
    sb.append(']');
    return sb.toString();
}
Also used : Candidate(org.jline.reader.Candidate)

Example 7 with Candidate

use of org.jline.reader.Candidate in project SpongeVanilla by SpongePowered.

the class ConsoleCommandCompleter method complete.

@Override
public void complete(LineReader reader, ParsedLine line, List<Candidate> candidates) {
    String buffer = line.line();
    boolean prefix;
    if (buffer.isEmpty() || buffer.charAt(0) != '/') {
        buffer = '/' + buffer;
        prefix = false;
    } else {
        prefix = true;
    }
    final String input = buffer;
    Future<List<String>> tabComplete = this.server.callFromMainThread(() -> this.server.getTabCompletions(this.server, input, this.server.getPosition(), false));
    try {
        for (String completion : tabComplete.get()) {
            if (completion.isEmpty()) {
                continue;
            }
            candidates.add(new Candidate(prefix || completion.charAt(0) != '/' ? completion : completion.substring(1)));
        }
    } catch (InterruptedException e) {
        Thread.currentThread().interrupt();
    } catch (ExecutionException e) {
        SpongeImpl.getLogger().error("Failed to tab complete", e);
    }
}
Also used : Candidate(org.jline.reader.Candidate) List(java.util.List) ExecutionException(java.util.concurrent.ExecutionException)

Example 8 with Candidate

use of org.jline.reader.Candidate in project batfish by batfish.

the class CommandCompleter method complete.

@Override
public void complete(LineReader lineReader, ParsedLine parsedLine, List<Candidate> candidates) {
    String buffer = parsedLine.word().trim();
    if (Strings.isNullOrEmpty(buffer)) {
        candidates.addAll(_commandStrs.stream().map(command -> new Candidate(command)).collect(Collectors.toList()));
    } else {
        for (String match : _commandStrs.tailSet(buffer)) {
            if (!match.startsWith(buffer)) {
                break;
            }
            candidates.add(new Candidate(match));
        }
    }
    // if the match was unique and the complete command was specified, print the command usage
    if (candidates.size() == 1 && candidates.get(0).displ().equals(buffer)) {
        candidates.clear();
        candidates.add(new Candidate(" " + Command.getUsageMap().get(Command.getNameMap().get(buffer)).getFirst()));
    }
}
Also used : Candidate(org.jline.reader.Candidate)

Aggregations

Candidate (org.jline.reader.Candidate)8 ArrayList (java.util.ArrayList)4 Path (java.nio.file.Path)2 List (java.util.List)2 ExecutionException (java.util.concurrent.ExecutionException)2 LineReader (org.jline.reader.LineReader)2 ParsedLine (org.jline.reader.ParsedLine)2 DefaultParser (org.jline.reader.impl.DefaultParser)2 Terminal (org.jline.terminal.Terminal)2 Test (org.junit.Test)2 DirectoriesCompleter (org.jline.builtins.Completers.DirectoriesCompleter)1 FilesCompleter (org.jline.builtins.Completers.FilesCompleter)1 LanternScheduler (org.lanternpowered.server.scheduler.LanternScheduler)1