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


Java ConsoleReader.setHistoryEnabled方法代碼示例

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


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

示例1: getSparql

import jline.console.ConsoleReader; //導入方法依賴的package包/類
@Override
public Optional<String> getSparql() throws IOException {
    final ConsoleReader reader = getReader();
    reader.setCopyPasteDetection(true); // disable tab completion from activating
    reader.setHistoryEnabled(false);    // don't store SPARQL fragments in the command history
    try {
        reader.println("Enter a SPARQL Query.");
        reader.println("Type '" + EXECUTE_COMMAND + "' to execute the current query.");
        reader.println("Type '" + CLEAR_COMMAND + "' to clear the current query.");
        reader.flush();

        final StringBuilder sb = new StringBuilder();
        String line = reader.readLine("SPARQL> ");
        while (!line.endsWith(CLEAR_COMMAND) && !line.endsWith(EXECUTE_COMMAND)) {
            sb.append(line).append("\n");
            line = reader.readLine("     -> ");
        }

        if (line.endsWith(EXECUTE_COMMAND)) {
            sb.append(line.substring(0, line.length() - EXECUTE_COMMAND.length()));
            return Optional.of(sb.toString());
        }
        return Optional.absent();
    } finally {
        reader.setHistoryEnabled(true);      // restore the ConsoleReader's settings
        reader.setCopyPasteDetection(false); // restore tab completion
    }
}
 
開發者ID:apache,項目名稱:incubator-rya,代碼行數:29,代碼來源:SparqlPrompt.java

示例2: 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

示例3: interactiveMode

import jline.console.ConsoleReader; //導入方法依賴的package包/類
private static boolean interactiveMode(JavaScriptEngine engine) {
    try {
        ConsoleReader reader = new ConsoleReader();
        reader.setPrompt(PromptNewLine);
        reader.addCompleter(new JavaScriptCompleter(engine));
        reader.setBellEnabled(false);
        reader.setHistoryEnabled(true);

        int lineNo = 1;
        int startLine = lineNo;

        String line;
        String source = "";

        PrintWriter out = new PrintWriter(reader.getOutput());

        boolean bContinueReading = false;

        while (!bExiting && (line = reader.readLine()) != null ) {
            source = source + line + "\n";
            lineNo++;

            bContinueReading = !engine.stringIsCompilableUnit(source);

            if (!bContinueReading) {
                try {
                    Object result = engine.runPartialScript(source, startLine);
                    if (result != null) {
                        out.println(engine.valueToString(result));
                    }
                } catch (ScriptException se) {
                    out.println(se.getMessage());
                }
                startLine = lineNo;
                source = "";
            }

            String prompt;
            if (bContinueReading) {
                prompt = PromptContinueLine;
            } else {
                prompt = PromptNewLine;
            }
            reader.setPrompt(prompt);
        }
        return true;
    } catch (IOException e) {
        System.err.println(e.getMessage());
        return false;
    }
}
 
開發者ID:loadtestgo,項目名稱:pizzascript,代碼行數:52,代碼來源:PizzaScript.java

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