/** * Construct an AggregateCompleter with the given collection of completers. * The completers will be used in the iteration order of the collection. * * @param completers the collection of completers */ public SortedAggregateCompleter(final Collection<Completer> completers) { checkNotNull(completers); this.completers.addAll(completers); }
/** * Gets the relative name to this item from the specified group. * * @param g * The {@link ItemGroup} instance used as context to evaluate the relative name of this item * @return * The name of the current item, relative to p. Nested {@link ItemGroup}s are separated by {@code /} character. * @since 1.419 * @return * String like "../foo/bar". * {@code null} if one of item parents is not an {@link Item}. */ @Nullable default String getRelativeNameFrom(@CheckForNull ItemGroup g) { return Functions.getRelativeNameFrom(this, g); }
/** * Restore the terminal. */ protected void restoreTerminal() { try { terminal.restore(); } catch (Exception e) { // ignore } if (terminal instanceof UnixTerminal) { // workaround for GRAILS-11494 try { new TerminalLineSettings().set("sane"); } catch (Exception e) { // ignore } } }
public String get(final String args) throws IOException, InterruptedException { checkNotNull(args); return stty(args); }
public String getPropertyAsString(String name) { checkNotNull(name); if (!fetchConfig(name)) { return null; } return getPropertyAsString(name, config); }
/** * @since 2.7 */ public static void reset() { Log.debug("Resetting"); properties = null; // force new properties to load getProperties(); }
private static MemoryHistory getHistory() { String historyFilePath = System.getenv("PRESTO_HISTORY_FILE"); File historyFile; if (isNullOrEmpty(historyFilePath)) { historyFile = new File(getUserHome(), ".presto_history"); } else { historyFile = new File(historyFilePath); } return getHistory(historyFile); }
/** * Create a console reader. * * @param systemIn The input stream * @return The console reader * @throws IOException if there is an error */ protected ConsoleReader createConsoleReader(InputStream systemIn) throws IOException { // need to swap out the output to avoid logging during init final PrintStream nullOutput = new PrintStream(new ByteArrayOutputStream()); final PrintStream originalOut = Log.getOutput(); try { Log.setOutput(nullOutput); ConsoleReader consoleReader = new ConsoleReader(systemIn, out); consoleReader.setExpandEvents(false); return consoleReader; } finally { Log.setOutput(originalOut); } }
/** * Returns the value of <tt>stty rows>/tt> param. */ @Override public int getHeight() { int h = settings.getProperty("rows"); return h < 1 ? DEFAULT_HEIGHT : h; }
public Completion(final List<CharSequence> candidates) { checkNotNull(candidates); this.candidates = new LinkedList<CharSequence>(candidates); }
public void set(final String... args) throws IOException, InterruptedException { checkNotNull(args); stty(args); }
/** * Short for {@code getRelativeNameFrom(item.getParent())} * * @return String like "../foo/bar". * {@code null} if one of item parents is not an {@link Item}. * @since 1.419 */ @Nullable default String getRelativeNameFrom(@Nonnull Item item) { return getRelativeNameFrom(item.getParent()); }
public void complete(final Completer completer, final String buffer, final int cursor) { checkNotNull(completer); this.cursor = completer.complete(buffer, cursor, candidates); } }
public void undef(final String name) throws IOException, InterruptedException { checkNotNull(name); stty(name, UNDEFINED); }
public StringsCompleter(final Collection<String> strings) { Preconditions.checkNotNull(strings); getStrings().addAll(strings); }
/** * @param strings The completer strings */ public StringsCompleter(final Collection<String> strings) { checkNotNull(strings); getStrings().addAll(strings); }
private int completeCollection(final String buffer, final int cursor, final Collection<CharSequence> candidates) { Preconditions.checkNotNull(candidates); if (buffer == null) { candidates.addAll(strings); } else { String part = buffer.substring(0, cursor); String bufferTmp = part.toUpperCase(); for (String match : strings.tailSet(part)) { String matchTmp = match.toUpperCase(); if (!matchTmp.startsWith(bufferTmp)) { break; } candidates.add(match); } } return candidates.isEmpty() ? -1 : 0; } }
@Override public int complete(String buffer, int cursor, List<CharSequence> candidates) { // buffer could be null checkNotNull(candidates); if (buffer == null) { candidates.addAll(commands); } else { String prefix = buffer; if (buffer.length() > cursor) { prefix = buffer.substring(0, cursor); } for (String match : commands.tailSet(prefix)) { if (!match.startsWith(prefix)) { break; } candidates.add(match); } } if (candidates.size() == 1) { candidates.set(0, candidates.get(0) + " "); } return candidates.isEmpty() ? -1 : 0; }
@Override public int complete(final String buffer, final int cursor, final List<CharSequence> candidates) { // buffer could be null checkNotNull(candidates); if (buffer == null) { candidates.addAll(getStrings()); } else { for (String match : getStrings().tailSet(buffer)) { if (!match.startsWith(buffer)) { break; } candidates.add(match); } } if (candidates.size() == 1) { candidates.set(0, candidates.get(0) + " "); } return candidates.isEmpty() ? -1 : 0; } }
@Override public int complete(final String buffer, final int cursor, final List<CharSequence> candidates) { // buffer could be null checkNotNull(candidates); List<Completion> completions = new ArrayList<Completion>(completers.size()); // Run each completer, saving its completion results int max = -1; for (Completer completer : completers) { Completion completion = new Completion(candidates); completion.complete(completer, buffer, cursor); // Compute the max cursor position max = Math.max(max, completion.cursor); completions.add(completion); } SortedSet<CharSequence> allCandidates = new TreeSet<>(); // Append candidates from completions which have the same cursor position as max for (Completion completion : completions) { if (completion.cursor == max) { allCandidates.addAll(completion.candidates); } } candidates.addAll(allCandidates); return max; }