本文整理汇总了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);
}
示例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();
}
}));
}
示例3: createConsoleReader
import jline.console.ConsoleReader; //导入方法依赖的package包/类
@Override
protected ConsoleReader createConsoleReader() {
ConsoleReader consoleReader = super.createConsoleReader();
consoleReader.setHistory(gfshHistory);
terminal = consoleReader.getTerminal();
return consoleReader;
}
示例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();
}
示例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());
}
示例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);
}
}
示例7: execute
import jline.console.ConsoleReader; //导入方法依赖的package包/类
@Override
public void execute(String[] args, ConsoleReader reader) throws Exception
{
logicalPlanRequestQueue.clear();
changingLogicalPlan = false;
reader.setHistory(topLevelHistory);
}
示例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());
}
}
}
示例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);
}
}
});
}