org.jline.reader.Completer Java Examples
The following examples show how to use
org.jline.reader.Completer.
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 Project: rug-cli Author: atomist-attic File: ShellUtils.java License: GNU General Public License v3.0 | 7 votes |
public static LineReader lineReader(File historyPath, Optional<SignalHandler> handler, Completer... completers) { // Protect the history file as may contain sensitive information FileUtils.setPermissionsToOwnerOnly(historyPath); // Create JLine LineReader History history = new DefaultHistory(); LineReader reader = LineReaderBuilder.builder().terminal(terminal(handler)).history(history) .parser(new DefaultParser()).variable(LineReader.HISTORY_FILE, historyPath) .completer(new AggregateCompleter(completers)).highlighter(new DefaultHighlighter()) .build(); history.attach(reader); setOptions(reader); return reader; }
Example #2
Source Project: presto Author: prestosql File: InputReader.java License: Apache License 2.0 | 6 votes |
public InputReader(Path historyFile, Completer... completers) throws IOException { Terminal terminal = TerminalBuilder.builder() .name("Presto") .build(); reader = LineReaderBuilder.builder() .terminal(terminal) .variable(HISTORY_FILE, historyFile) .variable(SECONDARY_PROMPT_PATTERN, colored("%P -> ")) .variable(BLINK_MATCHING_PAREN, 0) .parser(new InputParser()) .highlighter(new InputHighlighter()) .completer(new AggregateCompleter(completers)) .build(); reader.unsetOpt(HISTORY_TIMESTAMPED); }
Example #3
Source Project: presto Author: prestosql File: Completion.java License: Apache License 2.0 | 5 votes |
public static Completer commandCompleter() { return new StringsCompleter(ImmutableSet.<String>builder() .addAll(COMMANDS) .addAll(COMMANDS.stream() .map(value -> value.toLowerCase(ENGLISH)) .collect(toSet())) .build()); }
Example #4
Source Project: sshd-shell-spring-boot Author: anand1st File: TerminalProcessor.java License: Apache License 2.0 | 5 votes |
TerminalProcessor(Shell properties, Completer completer, List<BaseUserInputProcessor> userInputProcessors) { this.properties = properties; this.completer = completer; this.userInputProcessors = userInputProcessors; prompt = new AttributedStringBuilder() .style(getStyle(properties.getPrompt().getColor())) .append(properties.getPrompt().getTitle()) .append("> ") .style(AttributedStyle.DEFAULT) .toAnsi(); }
Example #5
Source Project: Arend Author: JetBrains File: SpecialCommandCompleter.java License: Apache License 2.0 | 5 votes |
public SpecialCommandCompleter( @NotNull Class<? extends ReplCommand> commandClass, @NotNull Completer completer ) { this.commandClass = commandClass; this.completer = completer; }
Example #6
Source Project: sqlline Author: julianhyde File: SqlLineCommandCompleter.java License: BSD 3-Clause "New" or "Revised" License | 5 votes |
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 #7
Source Project: sqlline Author: julianhyde File: AbstractCommandHandler.java License: BSD 3-Clause "New" or "Revised" License | 5 votes |
public AbstractCommandHandler(SqlLine sqlLine, String[] names, String helpText, List<Completer> completers) { this.sqlLine = sqlLine; name = names[0]; this.names = Arrays.asList(names); this.helpText = helpText; if (completers == null || completers.size() == 0) { this.parameterCompleters = Collections.singletonList(new NullCompleter()); } else { this.parameterCompleters = new ArrayList<>(completers); } }
Example #8
Source Project: sqlline Author: julianhyde File: SqlLineOpts.java License: BSD 3-Clause "New" or "Revised" License | 4 votes |
public List<Completer> resetOptionCompleters() { return Collections.singletonList(this); }
Example #9
Source Project: sqlline Author: julianhyde File: ReflectiveCommandHandler.java License: BSD 3-Clause "New" or "Revised" License | 4 votes |
public ReflectiveCommandHandler(SqlLine sqlLine, List<Completer> completers, String... cmds) { super(sqlLine, cmds, sqlLine.loc("help-" + cmds[0]), completers); }
Example #10
Source Project: sqlline Author: julianhyde File: ReflectiveCommandHandler.java License: BSD 3-Clause "New" or "Revised" License | 4 votes |
public ReflectiveCommandHandler(SqlLine sqlLine, Completer completer, String... cmds) { this(sqlLine, Collections.singletonList(completer), cmds); }
Example #11
Source Project: sqlline Author: julianhyde File: DatabaseConnection.java License: BSD 3-Clause "New" or "Revised" License | 4 votes |
Completer getSqlCompleter() { return sqlCompleter; }
Example #12
Source Project: sqlline Author: julianhyde File: AbstractCommandHandler.java License: BSD 3-Clause "New" or "Revised" License | 4 votes |
@Override public List<Completer> getParameterCompleters() { return parameterCompleters; }
Example #13
Source Project: sqlline Author: julianhyde File: Application.java License: BSD 3-Clause "New" or "Revised" License | 4 votes |
/** * Override this method to modify supported commands. * * <p>If method is not overridden, current state of commands will be * reset to default ({@code super.getCommandHandlers(sqlLine)}). * * <p>To update / leave current state, override this method * and use {@code sqlLine.getCommandHandlers()}. * * @param sqlLine SQLLine instance * * @return Collection of command handlers */ public Collection<CommandHandler> getCommandHandlers(SqlLine sqlLine) { TableNameCompleter tableCompleter = new TableNameCompleter(sqlLine); List<Completer> empty = Collections.emptyList(); final Map<String, OutputFormat> outputFormats = getOutputFormats(sqlLine); final Map<BuiltInProperty, Collection<String>> customPropertyCompletions = new HashMap<>(); customPropertyCompletions .put(BuiltInProperty.OUTPUT_FORMAT, outputFormats.keySet()); final CommandHandler[] handlers = { new ReflectiveCommandHandler(sqlLine, empty, "quit", "done", "exit"), new ReflectiveCommandHandler(sqlLine, new StringsCompleter(getConnectionUrlExamples()), "connect", "open"), new ReflectiveCommandHandler(sqlLine, empty, "nickname"), new ReflectiveCommandHandler(sqlLine, tableCompleter, "describe"), new ReflectiveCommandHandler(sqlLine, tableCompleter, "indexes"), new ReflectiveCommandHandler(sqlLine, tableCompleter, "primarykeys"), new ReflectiveCommandHandler(sqlLine, tableCompleter, "exportedkeys"), new ReflectiveCommandHandler(sqlLine, empty, "manual"), new ReflectiveCommandHandler(sqlLine, tableCompleter, "importedkeys"), new ReflectiveCommandHandler(sqlLine, empty, "procedures"), new ReflectiveCommandHandler(sqlLine, empty, "schemas"), new ReflectiveCommandHandler(sqlLine, empty, "tables"), new ReflectiveCommandHandler(sqlLine, empty, "typeinfo"), new ReflectiveCommandHandler(sqlLine, empty, "commandhandler"), new ReflectiveCommandHandler(sqlLine, tableCompleter, "columns"), new ReflectiveCommandHandler(sqlLine, empty, "reconnect"), new ReflectiveCommandHandler(sqlLine, tableCompleter, "dropall"), new ReflectiveCommandHandler(sqlLine, empty, "history"), new ReflectiveCommandHandler(sqlLine, new StringsCompleter(getMetadataMethodNames()), "metadata"), new ReflectiveCommandHandler(sqlLine, empty, "nativesql"), new ReflectiveCommandHandler(sqlLine, empty, "dbinfo"), new ReflectiveCommandHandler(sqlLine, empty, "rehash"), new ReflectiveCommandHandler(sqlLine, empty, "resize"), new ReflectiveCommandHandler(sqlLine, empty, "verbose"), new ReflectiveCommandHandler(sqlLine, new FileNameCompleter(), "run"), new ReflectiveCommandHandler(sqlLine, empty, "batch"), new ReflectiveCommandHandler(sqlLine, empty, "list"), new ReflectiveCommandHandler(sqlLine, empty, "all"), new ReflectiveCommandHandler(sqlLine, new ConnectionCompleter(sqlLine), "go", "#"), new ReflectiveCommandHandler(sqlLine, new FileNameCompleter(), "script") { @Override public boolean echoToFile() { return false; } }, new ReflectiveCommandHandler(sqlLine, new FileNameCompleter(), "record"), new ReflectiveCommandHandler(sqlLine, empty, "brief"), new ReflectiveCommandHandler(sqlLine, empty, "close"), new ReflectiveCommandHandler(sqlLine, empty, "closeall"), new ReflectiveCommandHandler(sqlLine, new StringsCompleter(getIsolationLevels()), "isolation"), new ReflectiveCommandHandler(sqlLine, new StringsCompleter(outputFormats.keySet()), "outputformat"), new ReflectiveCommandHandler(sqlLine, empty, "autocommit"), new ReflectiveCommandHandler(sqlLine, empty, "readonly"), new ReflectiveCommandHandler(sqlLine, empty, "commit"), new ReflectiveCommandHandler(sqlLine, new FileNameCompleter(), "properties"), new ReflectiveCommandHandler(sqlLine, empty, "rollback"), new ReflectiveCommandHandler(sqlLine, empty, "help", "?"), new ReflectiveCommandHandler(sqlLine, getOpts(sqlLine).setOptionCompleters(customPropertyCompletions), "set"), new ReflectiveCommandHandler(sqlLine, getOpts(sqlLine).resetOptionCompleters(), "reset"), new ReflectiveCommandHandler(sqlLine, empty, "save"), new ReflectiveCommandHandler(sqlLine, empty, "scan"), new ReflectiveCommandHandler(sqlLine, empty, "sql"), new ReflectiveCommandHandler(sqlLine, empty, "call"), new ReflectiveCommandHandler(sqlLine, empty, "appconfig"), new ReflectiveCommandHandler(sqlLine, empty, "rerun", "/"), new ReflectiveCommandHandler(sqlLine, empty, "prompthandler"), }; return Collections.unmodifiableList(Arrays.asList(handlers)); }
Example #14
Source Project: sqlline Author: julianhyde File: HelloWorld2CommandHandler.java License: BSD 3-Clause "New" or "Revised" License | 4 votes |
@Override public List<Completer> getParameterCompleters() { return Collections.emptyList(); }
Example #15
Source Project: sqlline Author: julianhyde File: CommandHandler.java License: BSD 3-Clause "New" or "Revised" License | 2 votes |
/** * Returns the completers that can handle parameters. * * @return Completers that can handle parameters */ List<Completer> getParameterCompleters();