use of org.jline.reader.Candidate in project felix by apache.
the class Builtin method __files.
public List<Candidate> __files(CommandSession session) {
ParsedLine line = Shell.getParsedLine(session);
LineReader reader = Shell.getReader(session);
List<Candidate> candidates = new ArrayList<>();
new FilesCompleter(session.currentDir()) {
@Override
protected String getDisplay(Terminal terminal, Path p) {
return getFileDisplay(session, p);
}
}.complete(reader, line, candidates);
return candidates;
}
use of org.jline.reader.Candidate in project felix by apache.
the class Builtin method __directories.
public List<Candidate> __directories(CommandSession session) {
ParsedLine line = Shell.getParsedLine(session);
LineReader reader = Shell.getReader(session);
List<Candidate> candidates = new ArrayList<>();
new DirectoriesCompleter(session.currentDir()) {
@Override
protected String getDisplay(Terminal terminal, Path p) {
return getFileDisplay(session, p);
}
}.complete(reader, line, candidates);
return candidates;
}
use of org.jline.reader.Candidate in project nifi by apache.
the class TestCLICompleter method testCompletionForSessionVariableWithFiles.
@Test
public void testCompletionForSessionVariableWithFiles() {
final String topCommand = "session";
final String subCommand = "set";
final DefaultParser.ArgumentList parsedLine = new DefaultParser.ArgumentList("", Arrays.asList(topCommand, subCommand, SessionVariable.NIFI_CLIENT_PROPS.getVariableName(), "src/test/resources/"), 3, -1, -1);
final List<Candidate> candidates = new ArrayList<>();
completer.complete(lineReader, parsedLine, candidates);
assertTrue(candidates.size() > 0);
boolean found = false;
for (Candidate candidate : candidates) {
if (candidate.value().equals("src/test/resources/test.properties")) {
found = true;
break;
}
}
assertTrue(found);
}
use of org.jline.reader.Candidate in project LanternServer by LanternPowered.
the class ConsoleCommandCompleter method complete.
@Override
public void complete(LineReader reader, ParsedLine line, List<Candidate> candidates) {
String buffer = line.line();
// The content with normalized spaces, the spaces are trimmed
// from the ends and there are never two spaces directly after each other
String command = StringUtils.normalizeSpace(buffer);
boolean hasPrefix = command.startsWith("/");
// Don't include the '/'
if (hasPrefix) {
command = command.substring(1);
}
// Keep the last space, it must be there!
if (buffer.endsWith(" ")) {
command = command + " ";
}
final String command0 = command;
final Future<List<String>> tabComplete = ((LanternScheduler) Sponge.getScheduler()).callSync(() -> Sponge.getCommandManager().getSuggestions(LanternConsoleSource.INSTANCE, command0, null));
try {
// Get the suggestions
final List<String> suggestions = tabComplete.get();
// If the suggestions are for the command and there was a prefix, then append the prefix
if (hasPrefix && command.split(" ").length == 1 && !command.endsWith(" ")) {
for (String completion : suggestions) {
if (!completion.isEmpty()) {
candidates.add(new Candidate('/' + completion));
}
}
} else {
for (String completion : suggestions) {
if (!completion.isEmpty()) {
candidates.add(new Candidate(completion));
}
}
}
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
} catch (ExecutionException e) {
Lantern.getLogger().error("Failed to tab complete", e);
}
}
use of org.jline.reader.Candidate in project nifi by apache.
the class TestCLICompleter method testCompletionWithFileArguments.
@Test
public void testCompletionWithFileArguments() {
final String topCommand = NiFiRegistryCommandGroup.REGISTRY_COMMAND_GROUP;
final String subCommand = "list-buckets";
final DefaultParser.ArgumentList parsedLine = new DefaultParser.ArgumentList("", Arrays.asList(topCommand, subCommand, "-p", "src/test/resources/"), 3, -1, -1);
final List<Candidate> candidates = new ArrayList<>();
completer.complete(lineReader, parsedLine, candidates);
assertTrue(candidates.size() > 0);
boolean found = false;
for (Candidate candidate : candidates) {
if (candidate.value().equals("src/test/resources/test.properties")) {
found = true;
break;
}
}
assertTrue(found);
}
Aggregations