|
Scala example source code file (CandidateListCompletionHandler.java)
The Scala CandidateListCompletionHandler.java source code/* * Copyright (c) 2002-2007, Marc Prud'hommeaux. All rights reserved. * * This software is distributable under the BSD license. See the terms of the * BSD license in the documentation provided with this software. */ package scala.tools.jline.console.completer; import scala.tools.jline.console.ConsoleReader; import scala.tools.jline.console.CursorBuffer; import java.io.IOException; import java.util.ArrayList; import java.util.Collection; import java.util.HashSet; import java.util.List; import java.util.Locale; import java.util.ResourceBundle; import java.util.Set; /** * A {@link CompletionHandler} that deals with multiple distinct completions * by outputting the complete list of possibilities to the console. This * mimics the behavior of the * <a href="http://www.gnu.org/directory/readline.html">readline library. * * @author <a href="mailto:mwp1@cornell.edu">Marc Prud'hommeaux * @author <a href="mailto:jason@planet57.com">Jason Dillon * @since 2.3 */ public class CandidateListCompletionHandler implements CompletionHandler { // TODO: handle quotes and escaped quotes && enable automatic escaping of whitespace public boolean complete(final ConsoleReader reader, final List<CharSequence> candidates, final int pos) throws IOException { CursorBuffer buf = reader.getCursorBuffer(); // if there is only one completion, then fill in the buffer if (candidates.size() == 1) { CharSequence value = candidates.get(0); // fail if the only candidate is the same as the current buffer if (value.equals(buf.toString())) { return false; } setBuffer(reader, value, pos); return true; } else if (candidates.size() > 1) { String value = getUnambiguousCompletions(candidates); setBuffer(reader, value, pos); } printCandidates(reader, candidates); // redraw the current console buffer reader.drawLine(); return true; } public static void setBuffer(final ConsoleReader reader, final CharSequence value, final int offset) throws IOException { while ((reader.getCursorBuffer().cursor > offset) && reader.backspace()) { // empty } reader.putString(value); reader.setCursorPosition(offset + value.length()); } /** * Print out the candidates. If the size of the candidates is greater than the * {@link ConsoleReader#getAutoprintThreshold}, they prompt with a warning. * * @param candidates the list of candidates to print */ public static void printCandidates(final ConsoleReader reader, Collection<CharSequence> candidates) throws IOException { Set<CharSequence> distinct = new HashSet Other Scala examples (source code examples)Here is a short list of links related to this Scala CandidateListCompletionHandler.java source code file: |
... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.