org.jline.builtins.Completers Java Examples

The following examples show how to use org.jline.builtins.Completers. 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: SqlLineCommandCompleter.java    From sqlline with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
SqlLineCommandCompleter(SqlLine sqlLine) {
  super(new LinkedList<>());
  List<Completer> completers = new LinkedList<>();

  for (CommandHandler commandHandler : sqlLine.getCommandHandlers()) {
    for (String cmd : commandHandler.getNames()) {
      List<Completer> compl = new LinkedList<>();
      final List<Completer> parameterCompleters =
          commandHandler.getParameterCompleters();
      if (parameterCompleters.size() == 1
          && parameterCompleters.iterator().next()
              instanceof Completers.RegexCompleter) {
        completers.add(parameterCompleters.iterator().next());
      } else {
        final String commandName = SqlLine.COMMAND_PREFIX + cmd;
        final String helpText = commandHandler.getHelpText();
        final int firstEndOfLineIndex = helpText.indexOf('\n');
        compl.add(
            new StringsCompleter(
                new SqlLineCandidate(sqlLine,
                    AttributedString.stripAnsi(commandName), commandName,
                    sqlLine.loc("command-name"),
                    firstEndOfLineIndex == -1
                        ? helpText
                        : helpText.substring(0, firstEndOfLineIndex),
                    // there could be whatever else instead helpText
                    // which is the same for commands with all theirs aliases
                    null, helpText, true)));
        compl.addAll(parameterCompleters);
        compl.add(new NullCompleter()); // last param no complete
        completers.add(new ArgumentCompleter(compl));
      }
    }
  }

  getCompleters().addAll(completers);
}
 
Example #2
Source File: ConsoleConfiguration.java    From sshd-shell-spring-boot with Apache License 2.0 4 votes vote down vote up
@Bean
TerminalProcessor terminalProcessor() {
    return new TerminalProcessor(properties.getShell(), new Completers.TreeCompleter(buildTextCompleters()),
            userInputProcessors);
}