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();
}
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);
}
}
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()));
}
}
Aggregations