當前位置: 首頁>>代碼示例>>Java>>正文


Java ConsoleReader.setHistory方法代碼示例

本文整理匯總了Java中jline.console.ConsoleReader.setHistory方法的典型用法代碼示例。如果您正苦於以下問題:Java ConsoleReader.setHistory方法的具體用法?Java ConsoleReader.setHistory怎麽用?Java ConsoleReader.setHistory使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在jline.console.ConsoleReader的用法示例。


在下文中一共展示了ConsoleReader.setHistory方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: buildInstance

import jline.console.ConsoleReader; //導入方法依賴的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);
}
 
開發者ID:spotify,項目名稱:heroic,代碼行數:19,代碼來源:HeroicInteractiveShell.java

示例2: JLineDevice

import jline.console.ConsoleReader; //導入方法依賴的package包/類
public JLineDevice(InputStream in, PrintStream out) throws IOException {
    File hfile = new File(HFILE);
    if (!hfile.exists()) {
        File parentFile = hfile.getParentFile();
        if (!parentFile.exists()) {
            parentFile.mkdirs();
        }
        hfile.createNewFile();
    }
    writer = new PrintWriter(out, true);
    reader = new ConsoleReader(in, out);
    history = new FileHistory(hfile);
    reader.setHistory(history);

    Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {
        @Override
        public void run() {
            writeHistory();
        }
    }));
}
 
開發者ID:ow2-proactive,項目名稱:scheduling,代碼行數:22,代碼來源:JLineDevice.java

示例3: createConsoleReader

import jline.console.ConsoleReader; //導入方法依賴的package包/類
@Override
protected ConsoleReader createConsoleReader() {
  ConsoleReader consoleReader = super.createConsoleReader();
  consoleReader.setHistory(gfshHistory);
  terminal = consoleReader.getTerminal();
  return consoleReader;
}
 
開發者ID:ampool,項目名稱:monarch,代碼行數:8,代碼來源:Gfsh.java

示例4: start

import jline.console.ConsoleReader; //導入方法依賴的package包/類
public void start() throws Exception {
    console = new ConsoleReader();
    console.getTerminal().setEchoEnabled(false);
    console.setPrompt("\u001B[32menkan\u001B[0m> ");
    History history = new FileHistory(new File(System.getProperty("user.home"), ".enkan_history"));
    console.setHistory(history);

    CandidateListCompletionHandler handler = new CandidateListCompletionHandler();
    console.setCompletionHandler(handler);
    consoleHandler = new ConsoleHandler(console);
    clientThread.execute(consoleHandler);
    clientThread.shutdown();
}
 
開發者ID:kawasima,項目名稱:enkan,代碼行數:14,代碼來源:ReplClient.java

示例5: testHistory

import jline.console.ConsoleReader; //導入方法依賴的package包/類
@Test
public void testHistory() throws IOException{
	
	ConsoleReader console= new ConsoleReader();
	//History history= new History(new File(System.getProperty("user.home") + File.separator + ".asciigenome_history"));
	History history= new MemoryHistory();
	history.add("foobar");
	history.add("baz");
	console.setHistory(history);
	System.out.println(console.getHistory());
}
 
開發者ID:dariober,項目名稱:ASCIIGenome,代碼行數:12,代碼來源:UtilsTest.java

示例6: setupHistory

import jline.console.ConsoleReader; //導入方法依賴的package包/類
private void setupHistory(ConsoleReader reader)
{
  File historyFile = new File(StramClientUtils.getUserDTDirectory(), "cli_history");
  historyFile.getParentFile().mkdirs();
  try {
    topLevelHistory = new FileHistory(historyFile);
    reader.setHistory(topLevelHistory);
    historyFile = new File(StramClientUtils.getUserDTDirectory(), "cli_history_clp");
    changingLogicalPlanHistory = new FileHistory(historyFile);
  } catch (IOException ex) {
    System.err.printf("Unable to open %s for writing.", historyFile);
  }
}
 
開發者ID:apache,項目名稱:apex-core,代碼行數:14,代碼來源:ApexCli.java

示例7: execute

import jline.console.ConsoleReader; //導入方法依賴的package包/類
@Override
public void execute(String[] args, ConsoleReader reader) throws Exception
{
  logicalPlanRequestQueue.clear();
  changingLogicalPlan = false;
  reader.setHistory(topLevelHistory);
}
 
開發者ID:apache,項目名稱:apex-core,代碼行數:8,代碼來源:ApexCli.java

示例8: run

import jline.console.ConsoleReader; //導入方法依賴的package包/類
private static void run() throws IOException {
    reader = new ConsoleReader();
    reader.addCompleter(new StringsCompleter("compileTest", "evalTest", "-acge", "getEnv()", "eval", "addKey"));

    FileHistory fileHistory = new FileHistory(new File("./sh/history.just"));
    reader.setHistoryEnabled(true);
    reader.setHistory(fileHistory);

    Runtime.getRuntime().addShutdownHook(new Thread(() -> {
        System.out.println("");
        System.out.println(ANSI_PURPLE + "Have a nice Day~~" + ANSI_RESET);
        try {
            fileHistory.flush();
        } catch (IOException ignored) {
        }
    }));

    String command;
    while ((command = reader.readLine(cyanPrint(JUST_EL))) != null) {

        if (command.equals("")) continue;
        else if (command.trim().equals("-q")) return;
        else if (resolveCommandLine(command)) continue;

        try {

            Queue<Token> tokens = lexer.scanner(command);

            reader.addCompleter(
                    new StringsCompleter(
                            tokens.stream()
                                  .map(Token::getText)
                                  .collect(toList())));

            AstNode node = parser.parser(tokens);

            if (openAst) {
                runAst(node);
            }

            if (openMockEval) {
                runEval(node, env);
            }

            if (openMockGenerate) {
                runCompile(node, env);
            }

        } catch (Throwable e) {
            AnsiConsole.out.println(ansi().fgRed().a(JUST_EL + e.getMessage()).reset().toString());
        }
    }
}
 
開發者ID:lfkdsk,項目名稱:Just-Evaluator,代碼行數:54,代碼來源:JustRepl.java

示例9: Init

import jline.console.ConsoleReader; //導入方法依賴的package包/類
private void Init(String accnt, String key, String cont) throws IOException
{
    conReader = new ConsoleReader();
    conReader.setPrompt("AzureShell> ");
    
     List<Completer> completors = new LinkedList<>();
     
    String currFileNameStr = "dir1";

    AzFileProvider azfp = new AzFileProvider();
    StaticUserAuthenticator auth = new StaticUserAuthenticator("", accnt, key);
    AzFileSystemConfigBuilder.getInstance().setUserAuthenticator(azfp.getDefaultFileSystemOptions(), auth); 
    
    DefaultFileSystemManager currMan = new DefaultFileSystemManager();
    currMan.addProvider(AzConstants.AZSBSCHEME, azfp);
    currMan.addProvider("file", new DefaultLocalFileProvider());
    currMan.init(); 
    
    mgr = currMan;
    //cwd = mgr.resolveFile(System.getProperty("user.dir"));c
    String currAzURL = String.format("%s://%s/%s/%s", 
                       AzConstants.AZSBSCHEME, accnt, cont, currFileNameStr);
    cwd = mgr.resolveFile(currAzURL);
    
    completors.add(new FileNameCompleter());
    completors.add(new StringsCompleter(AzConstants.AZSBSCHEME, "file://", currAzURL));
    AggregateCompleter aggComp = new AggregateCompleter(completors);
    ArgumentCompleter argComp = new ArgumentCompleter(aggComp);
    argComp.setStrict(false);
    conReader.addCompleter(argComp);
    
    Path histPath = Paths.get(System.getProperty("user.home"), ".simpleshellhist");
    File histFile = histPath.toFile();
    FileHistory fh = new FileHistory(histFile);
    conReader.setHistory(fh);
    conReader.setHistoryEnabled(true);
    
    Runtime.getRuntime().addShutdownHook(
            new Thread() 
            {
                @Override
                public void run() 
                {
                    try
                    {
                        ((FileHistory)conReader.getHistory()).flush();
                    }
                    catch (IOException ex)
                    {
                        log.error("Error saving history", ex);
                    }
                }
            });
    
}
 
開發者ID:kervinpierre,項目名稱:vfs-azure,代碼行數:56,代碼來源:SimpleShell.java


注:本文中的jline.console.ConsoleReader.setHistory方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。