當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。