本文整理汇总了Java中jline.console.completer.Completer类的典型用法代码示例。如果您正苦于以下问题:Java Completer类的具体用法?Java Completer怎么用?Java Completer使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Completer类属于jline.console.completer包,在下文中一共展示了Completer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getConsole
import jline.console.completer.Completer; //导入依赖的package包/类
public ConsoleReader getConsole() throws IOException {
if (console == null) {
// console = new ConsoleReader(System.in, System.out);
console = new ConsoleReader();
}
String osName = builtIn.getLocalOsName();
if (osName.toLowerCase().contains("win")) {
System.out.println("-----your Console is terrible.-----\n"
+ "if it reports some errors, just ignore it.");
console.setPrompt("[email protected]" + builtIn.getHostname() + "> ");
} else {
console.setPrompt("\u001B[33mjweevely\u001B[[email protected]"
+ builtIn.getHostname() + "\u001B[33m>\u001B[0m ");
}
List<Completer> completors = new ArrayList<Completer>();
completors.add(new StringsCompleter(BuiltIn.BUILTIN_FUNCTION));
completors.add(new FileNameCompleter());
completors.add(new NullCompleter());
console.addCompleter(new ArgumentCompleter(completors));
return console;
}
示例2: complete
import jline.console.completer.Completer; //导入依赖的package包/类
@Override
public int complete(String buffer, int cursor, List<CharSequence> candidates) {
int completionIndex = super.complete(buffer, cursor, candidates);
int spaceIndex = buffer.indexOf(' ');
String commandName = (spaceIndex == -1) ? "" : buffer.substring(0, spaceIndex);
if (!"".equals(commandName.trim())) {
for (Command command : this.commands) {
if (command.getName().equals(commandName)) {
if (cursor == buffer.length() && buffer.endsWith(" ")) {
printUsage(command);
break;
}
Completer completer = this.commandCompleters.get(command.getName());
if (completer != null) {
completionIndex = completer.complete(buffer, cursor, candidates);
break;
}
}
}
}
return completionIndex;
}
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:23,代码来源:CommandCompleter.java
示例3: complete
import jline.console.completer.Completer; //导入依赖的package包/类
/**
* Use the completers to modify the buffer with the appropriate completions.
*
* @return true if successful
*/
protected boolean complete() throws IOException {
// debug ("tab for (" + buf + ")");
if (completers.size() == 0) {
return false;
}
List<CharSequence> candidates = new LinkedList<CharSequence>();
String bufstr = buf.buffer.toString();
int cursor = buf.cursor;
int position = -1;
for (Completer comp : completers) {
if ((position = comp.complete(bufstr, cursor, candidates)) != -1) {
break;
}
}
return candidates.size() != 0 && getCompletionHandler().complete(this, candidates, position);
}
示例4: printCompletionCandidates
import jline.console.completer.Completer; //导入依赖的package包/类
protected void printCompletionCandidates() throws IOException {
// debug ("tab for (" + buf + ")");
if (completers.size() == 0) {
return;
}
List<CharSequence> candidates = new LinkedList<CharSequence>();
String bufstr = buf.buffer.toString();
int cursor = buf.cursor;
for (Completer comp : completers) {
if (comp.complete(bufstr, cursor, candidates) != -1) {
break;
}
}
CandidateListCompletionHandler.printCandidates(this, candidates);
drawLine();
}
示例5: SqlLineCommandCompleter
import jline.console.completer.Completer; //导入依赖的package包/类
public SqlLineCommandCompleter(SqlLine sqlLine) {
List<ArgumentCompleter> completers = new LinkedList<ArgumentCompleter>();
for (CommandHandler commandHandler : sqlLine.commandHandlers) {
for (String cmd : commandHandler.getNames()) {
List<Completer> compl = new LinkedList<Completer>();
compl.add(new StringsCompleter(SqlLine.COMMAND_PREFIX + cmd));
compl.addAll(commandHandler.getParameterCompleters());
compl.add(new NullCompleter()); // last param no complete
completers.add(new ArgumentCompleter(compl));
}
}
getCompleters().addAll(completers);
}
示例6: getCompleter
import jline.console.completer.Completer; //导入依赖的package包/类
@Override
public Completer getCompleter(final TJContext tjContext) {
return new Completer() {
@Override
public int complete(String buffer, int cursor, List<CharSequence> candidates) {
buffer = buffer.trim().toLowerCase();
if (buffer.indexOf(' ') < 0) {
for (CmdDescription h : cmdDescriptions) {
if (h.canBeUsed(tjContext) && h.getPrefix().toLowerCase().startsWith(buffer) && !h.getPrefix().equalsIgnoreCase(buffer)) {
candidates.add(h.getPrefix());
}
}
}
return (candidates.isEmpty() || buffer.length() == 0) ? -1 /* go on */ : 0;
}
};
}
示例7: getCompleter
import jline.console.completer.Completer; //导入依赖的package包/类
@Override
public Completer getCompleter(final TJContext tjContext) {
return new Completer() {
@Override
public int complete(String buffer, int cursor, List<CharSequence> candidates) {
if (matches(buffer)) {
String namePrefix = buffer.substring(prefix.length()).trim();
for (String key : tjContext.getEnvironment().keySet()) {
if (key.startsWith(namePrefix)) {
candidates.add(" " + key + "=");
}
}
return prefix.length();
}
return -1;
}
};
}
示例8: getCompleter
import jline.console.completer.Completer; //导入依赖的package包/类
@Override
public Completer getCompleter(final TJContext ctx) {
return new Completer() {
@Override
public int complete(String buffer, int cursor, List<CharSequence> candidates) {
if (matches(buffer) && ctx.isConnected()) {
String urlPrefix = extractURL(buffer);
try {
for (String s : names(ctx)) {
if (s.startsWith(urlPrefix)) {
candidates.add(" " + s);
}
}
} catch (IOException e) {
logger.throwing(getClass().getName(), "complete - Error receiving bean names from JMX Server", e);
}
return prefix.length();
} else {
return -1;
}
}
};
}
示例9: resetCompletors
import jline.console.completer.Completer; //导入依赖的package包/类
protected void resetCompletors() {
removeAllcompleters();
addcompleters(new AggregateCompleter(
Collections2.transform(commandMappings.keySet(), new Function<Call, Completer>() {
@Override
public Completer apply(final Call input) {
return new ArgumentCompleter(
ImmutableList.<Completer>builder()
.add(new StringsCompleter(input.commandName()))
.add(input.completers())
.build()
);
}
})
));
}
示例10: getCompleterForMethod
import jline.console.completer.Completer; //导入依赖的package包/类
/**
* Erzeugt einen Completer für eine CliCommand-Methode. Dazu wird die
* entsprechende Annotation ausgelesen und mit der dort angegeben
* Factory-Klasse der Completer erzeugt.
*
* @param mtd
* Methode
* @return Der Completer, falls die Annotation vorhanden war und dieser
* erzeugt werden konnte; andernfalls wird ein
* <tt>NullCompleter</tt> zurückgegeben.
*/
private static Completer getCompleterForMethod(Method mtd) {
Completer completer = NullCompleter.INSTANCE;
if (mtd.isAnnotationPresent(ParamCompleter.class)) {
try {
ParamCompleter anno = mtd.getAnnotation(ParamCompleter.class);
Class<? extends CompleterFactory> complFacCls = anno.value();
CompleterFactory complFac = complFacCls.newInstance();
completer = complFac.getCompleter();
} catch (InstantiationException | IllegalAccessException e) {
log.log(Level.WARNING,
"Could not initialise completer for command", e);
}
}
return completer;
}
示例11: setUpCompletors
import jline.console.completer.Completer; //导入依赖的package包/类
/**
* sets up the completors that a user can use with tab
* @param reader the current reader
*/
private void setUpCompletors(ConsoleReader reader) {
List<Completer> completors = new LinkedList<>();
completors.add(new StringsCompleter("create", "start", "stop", "exit", "help", "cls"));
for (Completer c : completors) {
reader.addCompleter(c);
}
}
示例12: updateCompleter
import jline.console.completer.Completer; //导入依赖的package包/类
private void updateCompleter(ConsoleReader reader)
{
List<Completer> completers = new ArrayList<>(reader.getCompleters());
for (Completer c : completers) {
reader.removeCompleter(c);
}
setupCompleter(reader);
}
示例13: LineReader
import jline.console.completer.Completer; //导入依赖的package包/类
LineReader(History history, Completer... completers)
throws IOException
{
setExpandEvents(false);
setBellEnabled(true);
setHandleUserInterrupt(true);
setHistory(history);
setHistoryEnabled(false);
for (Completer completer : completers) {
addCompleter(completer);
}
}
示例14: readLine
import jline.console.completer.Completer; //导入依赖的package包/类
private static String readLine(ConsoleReader console) throws IOException {
ConsoleUtils.begin(31);
ConsoleUtils.println(">>>");
ConsoleUtils.end();
List<Completer> completors = new LinkedList<Completer>();
// completors.add(new AnsiStringsCompleter("\u001B[1mfoo\u001B[0m",
// "bar", "\u001B[32mbaz\u001B[0m"));
CandidateListCompletionHandler handler = new CandidateListCompletionHandler();
handler.setStripAnsi(true);
console.setCompletionHandler(handler);
for (Completer c : completors) {
console.addCompleter(c);
}
// History h = console.getHistory();
// ("hoge\rhoge");
StringBuilder sb = new StringBuilder();
while (true) {
String line = console.readLine();
if (line == null) {
return null;
}
if (line.equals("")) {
return sb.toString();
}
sb.append(line);
sb.append("\n");
}
// h = console.getHistory();
}
示例15: shouldSetCompleters
import jline.console.completer.Completer; //导入依赖的package包/类
@Test
public void shouldSetCompleters() {
Completer completer = new FileNameCompleter();
underTest.setCompleters(ImmutableList.<Completer>builder().add(completer).build());
verify(consoleReader).addCompleter(completerCaptor.capture());
assertThat(completerCaptor.getValue(), is(completer));
}