当前位置: 首页>>代码示例>>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;未经允许,请勿转载。