当前位置: 首页>>代码示例>>Java>>正文


Java Completer类代码示例

本文整理汇总了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;
}
 
开发者ID:needle-wang,项目名称:jweevely,代码行数:24,代码来源:JweevelyClient.java

示例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);
}
 
开发者ID:AcademicTorrents,项目名称:AcademicTorrents-Downloader,代码行数:26,代码来源:ConsoleReader.java

示例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();
}
 
开发者ID:AcademicTorrents,项目名称:AcademicTorrents-Downloader,代码行数:19,代码来源:ConsoleReader.java

示例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);
}
 
开发者ID:mozafari,项目名称:verdict,代码行数:17,代码来源:SqlLineCommandCompleter.java

示例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;
        }
    };
}
 
开发者ID:m-szalik,项目名称:tjconsole,代码行数:18,代码来源:HelpCommandDefinition.java

示例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;
        }
    };
}
 
开发者ID:m-szalik,项目名称:tjconsole,代码行数:19,代码来源:EnvCommandDefinition.java

示例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;
            }
        }
    };
}
 
开发者ID:m-szalik,项目名称:tjconsole,代码行数:24,代码来源:UseCommandDefinition.java

示例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()
                );
            }
        })
    ));
}
 
开发者ID:shopzilla,项目名称:hadoop-in-a-box,代码行数:17,代码来源:HadoopREPL.java

示例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;
}
 
开发者ID:fabianlipp,项目名称:jnami,代码行数:27,代码来源:CliParser.java

示例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);
    }
}
 
开发者ID:StuPro-TOSCAna,项目名称:stupro_toscana_vorprojekt,代码行数:12,代码来源:Controller.java

示例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);
}
 
开发者ID:apache,项目名称:apex-core,代码行数:9,代码来源:ApexCli.java

示例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);
    }
}
 
开发者ID:y-lan,项目名称:presto,代码行数:13,代码来源:LineReader.java

示例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();
}
 
开发者ID:nez-peg,项目名称:konoha,代码行数:31,代码来源:Main.java

示例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));
}
 
开发者ID:dfoerderreuther,项目名称:console-builder,代码行数:8,代码来源:ConsoleReaderWrapperTest.java


注:本文中的jline.console.completer.Completer类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。