本文整理匯總了Java中jline.console.completer.StringsCompleter類的典型用法代碼示例。如果您正苦於以下問題:Java StringsCompleter類的具體用法?Java StringsCompleter怎麽用?Java StringsCompleter使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
StringsCompleter類屬於jline.console.completer包,在下文中一共展示了StringsCompleter類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getConsole
import jline.console.completer.StringsCompleter; //導入依賴的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: connect
import jline.console.completer.StringsCompleter; //導入依賴的package包/類
public void connect(int port) throws IOException {
socket = new Socket("localhost", port);
packer = msgpack.createPacker(socket.getOutputStream());
unpacker = msgpack.createUnpacker(socket.getInputStream());
packer.write("/?\n");
List<String> availableCommands = new ArrayList<>();
while (true) {
ReplResponse res = unpacker.read(ReplResponse.class);
if (res.getOut() != null) {
Stream.of(res.getOut())
.map(String::trim)
.filter(s -> s.startsWith("/"))
.forEach(availableCommands::add);
}
if (res.getStatus().contains(DONE)) {
break;
}
}
console.addCompleter(new StringsCompleter(availableCommands));
console.println("Connected to server (port = " + port +")");
console.flush();
}
示例3: CommandCompleter
import jline.console.completer.StringsCompleter; //導入依賴的package包/類
public CommandCompleter(ConsoleReader consoleReader,
ArgumentDelimiter argumentDelimiter, Iterable<Command> commands) {
this.console = consoleReader;
List<String> names = new ArrayList<String>();
for (Command command : commands) {
this.commands.add(command);
names.add(command.getName());
List<String> options = new ArrayList<String>();
for (OptionHelp optionHelp : command.getOptionsHelp()) {
options.addAll(optionHelp.getOptions());
}
AggregateCompleter argumentCompleters = new AggregateCompleter(
new StringsCompleter(options), new FileNameCompleter());
ArgumentCompleter argumentCompleter = new ArgumentCompleter(argumentDelimiter,
argumentCompleters);
argumentCompleter.setStrict(false);
this.commandCompleters.put(command.getName(), argumentCompleter);
}
getStrings().addAll(names);
}
開發者ID:vikrammane23,項目名稱:https-github.com-g0t4-jenkins2-course-spring-boot,代碼行數:21,代碼來源:CommandCompleter.java
示例4: initConsole
import jline.console.completer.StringsCompleter; //導入依賴的package包/類
public static ConsoleReader initConsole() throws IOException, InvalidColourException{
Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {
public void run() {
System.out.print("\033[0m"); // On exit turn off all formatting
}
}));
ConsoleReader console= new ConsoleReader();
try {
// Autcomplete commands with length > x
for(CommandHelp x : CommandList.commandHelpList()){
if(x.getName().length() > 2){
console.addCompleter(new StringsCompleter(x.getName()));
}
}
} catch (InvalidCommandLineException e) {
e.printStackTrace();
}
console.setExpandEvents(false);
return console;
}
示例5: CommandCompleter
import jline.console.completer.StringsCompleter; //導入依賴的package包/類
public CommandCompleter(ConsoleReader consoleReader,
ArgumentDelimiter argumentDelimiter, Iterable<Command> commands) {
this.console = consoleReader;
List<String> names = new ArrayList<String>();
for (Command command : commands) {
this.commands.add(command);
names.add(command.getName());
List<String> options = new ArrayList<String>();
for (OptionHelp optionHelp : command.getOptionsHelp()) {
options.addAll(optionHelp.getOptions());
}
AggregateCompleter arguementCompleters = new AggregateCompleter(
new StringsCompleter(options), new FileNameCompleter());
ArgumentCompleter argumentCompleter = new ArgumentCompleter(argumentDelimiter,
arguementCompleters);
argumentCompleter.setStrict(false);
this.commandCompleters.put(command.getName(), argumentCompleter);
}
getStrings().addAll(names);
}
示例6: buildInstance
import jline.console.completer.StringsCompleter; //導入依賴的package包/類
public static HeroicInteractiveShell buildInstance(
final List<CommandDefinition> commands, FileInputStream input
) throws Exception {
final ConsoleReader reader = new ConsoleReader("heroicsh", input, System.out, null);
final FileHistory history = setupHistory(reader);
if (history != null) {
reader.setHistory(history);
}
reader.setPrompt(String.format("heroic> "));
reader.addCompleter(new StringsCompleter(
ImmutableList.copyOf(commands.stream().map((d) -> d.getName()).iterator())));
reader.setHandleUserInterrupt(true);
return new HeroicInteractiveShell(reader, commands, history);
}
示例7: readCommands
import jline.console.completer.StringsCompleter; //導入依賴的package包/類
public void readCommands() {
try {
console = new ConsoleReader();
List commandNames = new ArrayList();
for (Command c : commands) {
c.setupCompleter();
commandNames.add(c.names[0]);
}
console.addCompleter(new StringsCompleter(commandNames));
console.setPrompt("proptester> ");
String line;
while ((line = console.readLine()) != null) {
processCommand(line);
}
} catch (IOException io) {
io.printStackTrace();
}
}
示例8: initConsole
import jline.console.completer.StringsCompleter; //導入依賴的package包/類
/**
* Console initialisation.
*/
private void initConsole() {
try {
reader = new ConsoleReader();
final StringsCompleter strCompleter = new StringsCompleter(
"examples", "quit", "exit", "select", "insert", "update", "drop", "show" );
reader.setPrompt(" > ");
reader.addCompleter(strCompleter);
}
catch (IOException e) {
logger.error("Init de la console", e);
System.exit(1);
}
}
示例9: SqlLineCommandCompleter
import jline.console.completer.StringsCompleter; //導入依賴的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);
}
示例10: console
import jline.console.completer.StringsCompleter; //導入依賴的package包/類
private void console() throws Exception {
reader = new ConsoleReader();
consoleMode = true;
reader.setBellEnabled(false);
// List<Completer> completors = new LinkedList<>();
List<String> commandNames = commands.stream().map(Command::getName).collect(toList());
commandNames.add("exit");
reader.addCompleter(new StringsCompleter(commandNames));
// reader.addCompleter(new ArgumentCompleter(completors));
String line;
PrintWriter out = new PrintWriter(reader.getOutput());
while ((line = readLine("hightide")) != null) {
if ("exit".equals(line)) {
exit();
return;
} else {
Boolean failed = !runCommand(line);
if (failed) {
System.out
.println("Invalid command, For assistance press TAB or type \"help\" then hit ENTER.");
}
}
out.flush();
}
}
示例11: resetCompletors
import jline.console.completer.StringsCompleter; //導入依賴的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()
);
}
})
));
}
示例12: Init
import jline.console.completer.StringsCompleter; //導入依賴的package包/類
/** Client initialization */
public void Init( String url ) {
if( url != null && !url.equals( "" ) )
_server_url = url;
try {
_servidor = new XmlRpcClientBase( _server_url );
_reader = new ConsoleReader();
_reader.setBellEnabled( false );
List completors = new LinkedList();
completors.add( new StringsCompleter( _commandList ) );
_reader.addCompleter( new ArgumentCompleter( completors ) );
} catch (Exception exception) {
System.err.println("error: " + exception.toString());
}
}
示例13: setUpCompletors
import jline.console.completer.StringsCompleter; //導入依賴的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);
}
}
示例14: testStringsCompleter
import jline.console.completer.StringsCompleter; //導入依賴的package包/類
@Test
public void testStringsCompleter() {
StringsCompleter completer = new StringsCompleter("abc", "abd", "ac");
List<CharSequence> candidates = new ArrayList<>();
completer.complete("a", 1, candidates);
System.out.println(candidates);
candidates.clear();
completer.complete("ab", 2, candidates);
System.out.println(candidates);
}
示例15: init
import jline.console.completer.StringsCompleter; //導入依賴的package包/類
public void init() {
System.setProperty("library.jansi.version", "JaPS");
AnsiConsole.systemInstall();
try {
consoleReader = new ConsoleReader();
consoleReader.setExpandEvents(false);
} catch (IOException e) {
e.printStackTrace();
}
// Setup logging system
logger = new JaPSLogger(consoleReader);
System.setErr(new PrintStream(new LoggingOutputStream(logger, Level.SEVERE), true));
System.setOut(new PrintStream(new LoggingOutputStream(logger, Level.INFO), true));
// Register command
commandManager = new CommandManager();
commandManager.addCommand(new HelpCommand("help", new String[]{"h"}, "Show this output"));
commandManager.addCommand(new SubCommand("sub", new String[]{"s", "subscribe"}, "Subscribe a channel and view it's prepareCacheSync passing"));
commandManager.addCommand(new UnsubCommand("unsub", new String[]{}, "Unsubscribe previous subscribed channels"));
commandManager.addCommand(new EndCommand("end", new String[]{"stop"}, "Shutdown the server"));
commandManager.addCommand(new SetCommand("set", new String[]{"add"}, "Sets a key and value"));
commandManager.addCommand(new GetCommand("get", new String[]{}, "Gets a value from a key"));
commandManager.addCommand(new DeleteCommand("delete", new String[]{"remove", "del", "rm"}, "Gets a value from a key"));
commandManager.addCommand(new SnapshotCommand("snapshot", new String[]{}, "Takes a memory snapshot"));
// Autocomplete commands
consoleReader.addCompleter(new StringsCompleter(commandManager.getCommands().stream().map(Command::getName).collect(Collectors.toList())));
// Autocomplete files
consoleReader.addCompleter(new FileNameCompleter());
logger.info("Initialized");
}