当前位置: 首页>>代码示例>>Java>>正文


Java History类代码示例

本文整理汇总了Java中jline.console.history.History的典型用法代码示例。如果您正苦于以下问题:Java History类的具体用法?Java History怎么用?Java History使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


History类属于jline.console.history包,在下文中一共展示了History类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: searchBackwards

import jline.console.history.History; //导入依赖的package包/类
public int searchBackwards(String searchTerm, int startIndex, boolean startsWith) {
    ListIterator<History.Entry> it = history.entries(startIndex);
    while (it.hasPrevious()) {
        History.Entry e = it.previous();
        if (startsWith) {
            if (e.value().toString().startsWith(searchTerm)) {
                return e.index();
            }
        } else {
            if (e.value().toString().contains(searchTerm)) {
                return e.index();
            }
        }
    }
    return -1;
}
 
开发者ID:AcademicTorrents,项目名称:AcademicTorrents-Downloader,代码行数:17,代码来源:ConsoleReader.java

示例2: searchForwards

import jline.console.history.History; //导入依赖的package包/类
public int searchForwards(String searchTerm, int startIndex, boolean startsWith) {
    if (startIndex >= history.size()) {
        startIndex = history.size() - 1;
    }

    ListIterator<History.Entry> it = history.entries(startIndex);

    if (searchIndex != -1 && it.hasNext()) {
        it.next();
    }

    while (it.hasNext()) {
        History.Entry e = it.next();
        if (startsWith) {
            if (e.value().toString().startsWith(searchTerm)) {
                return e.index();
            }
        } else {
            if (e.value().toString().contains(searchTerm)) {
                return e.index();
            }
        }
    }
    return -1;
}
 
开发者ID:AcademicTorrents,项目名称:AcademicTorrents-Downloader,代码行数:26,代码来源:ConsoleReader.java

示例3: getJLineHistory

import jline.console.history.History; //导入依赖的package包/类
/**
 * Load the History from disk if a $HOME directory is defined, otherwise fall back to using an in-memory history object
 * 
 * @return
 * @throws IOException
 */
protected History getJLineHistory() throws IOException {
  String home = System.getProperty("HOME");
  if (null == home) {
    home = System.getenv("HOME");
  }
  
  // Get the home directory
  File homeDir = new File(home);
  
  // Make sure it actually exists
  if (homeDir.exists() && homeDir.isDirectory()) {
    // Check for, and create if necessary, the directory for cosmos to use
    File historyDir = new File(homeDir, ".cosmos");
    if (!historyDir.exists() && !historyDir.mkdirs()) {
      log.warn("Could not create directory for history at {}, using temporary history.", historyDir);
    }
    
    // Get a file for jline history
    File historyFile = new File(historyDir, "history");
    return new FileHistory(historyFile);
  } else {
    log.warn("Home directory not found: {}, using temporary history", homeDir);
    return new MemoryHistory();
  }
}
 
开发者ID:joshelser,项目名称:cosmos,代码行数:32,代码来源:CosmosConsole.java

示例4: createMainEnvironment

import jline.console.history.History; //导入依赖的package包/类
protected CliEnvironment createMainEnvironment(final AtomicReference<InputReader> dynamicInputReaderRef,
                                               final AtomicReference<History> dynamicHistoryAtomicReference) {
    final Map<String, ?> data = new HashMap<String, Object>();
    return new CliEnv() {
        @Override
        public History history() {
            return dynamicHistoryAtomicReference.get();
        }

        @Override
        public InputReader reader() {
            return dynamicInputReaderRef.get();
        }

        @Override
        public Map<String, ?> userData() {
            return data;
        }
    };
}
 
开发者ID:tomitribe,项目名称:crest,代码行数:21,代码来源:CrestCli.java

示例5: start

import jline.console.history.History; //导入依赖的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

示例6: getCommandHistory

import jline.console.history.History; //导入依赖的package包/类
/**Read the asciigenome history file and put it a list as current history. Or
 * return empty history file does not exist or can't be read. 
 * */
public History getCommandHistory(){
	History cmdHistory= new MemoryHistory();
	for(String x : this.getCommands()){
		cmdHistory.add(x);
	}
	return cmdHistory;
}
 
开发者ID:dariober,项目名称:ASCIIGenome,代码行数:11,代码来源:ASCIIGenomeHistory.java

示例7: testHistory

import jline.console.history.History; //导入依赖的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

示例8: LineReader

import jline.console.history.History; //导入依赖的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

示例9: history

import jline.console.history.History; //导入依赖的package包/类
public void history(String line, DispatchCallback callback) {
    int index = 1;
    for (History.Entry entry : sqlLine.getConsoleReader().getHistory()) {
        index++;
        sqlLine.output(
                sqlLine.getColorBuffer().pad(index + ".", 6)
                .append(entry.toString()));
    }
    callback.setToSuccess();
}
 
开发者ID:mozafari,项目名称:verdict,代码行数:11,代码来源:Commands.java

示例10: testAddToHistory

import jline.console.history.History; //导入依赖的package包/类
@Test
public void testAddToHistory() throws Exception{
    History h = c.getReader().getHistory();
    c.clearHistory();
    c.addToHistory("Test");
    Assert.assertEquals("Test", h.get(0));
}
 
开发者ID:vladimirvivien,项目名称:clamshell-cli,代码行数:8,代码来源:CliConsoleTest.java

示例11: sendHistory

import jline.console.history.History; //导入依赖的package包/类
private void sendHistory() throws IOException {
	History history = console.getHistory();
	ListIterator<Entry> entries = history.entries();
	HistoryResponse response = new HistoryResponse();

	response.setHistoryLines(new ArrayList<String>(history.size()));

	while(entries.hasNext()){
		Entry entry = entries.next();
		response.getHistoryLines().set(entry.index(), entry.value().toString());
	}

	connector.send(response);
}
 
开发者ID:rainu,项目名称:jsimpleshell-rc,代码行数:15,代码来源:Handshaker.java

示例12: history

import jline.console.history.History; //导入依赖的package包/类
public void history(String line, DispatchCallback callback) {
  int index = 1;
  for (History.Entry entry : sqlLine.getConsoleReader().getHistory()) {
    index++;
    sqlLine.output(
        sqlLine.getColorBuffer().pad(index + ".", 6)
            .append(entry.toString()));
  }
  callback.setToSuccess();
}
 
开发者ID:julianhyde,项目名称:sqlline,代码行数:11,代码来源:Commands.java

示例13: history

import jline.console.history.History; //导入依赖的package包/类
protected Iterable<String> history() {
    return Lists.newArrayList(Iterators.transform(consoleReader.getHistory().entries(), new Function<History.Entry, String>() {
        @Override
        public String apply(final History.Entry entry) {
            return entry.value().toString();
        }
    }));
}
 
开发者ID:shopzilla,项目名称:hadoop-in-a-box,代码行数:9,代码来源:REPL.java

示例14: getHistoryEntries

import jline.console.history.History; //导入依赖的package包/类
@Override
public Iterator<CharSequence> getHistoryEntries() {
    if (fileHistory == null) {
        return new ArrayList<CharSequence>().iterator();
    }
    return Iterators.transform(fileHistory.iterator(), new Function<History.Entry, CharSequence>() {
        @Override
        public CharSequence apply(jline.console.history.History.Entry entry) {
            return entry.value();
        }
    });
}
 
开发者ID:javanna,项目名称:elasticshell,代码行数:13,代码来源:JLineConsole.java

示例15: writeYamlHistory

import jline.console.history.History; //导入依赖的package包/类
/** On shutdown, prepare and write the history file. Not that the existing 
 * yaml file is overwritten.  */
private static void writeYamlHistory(final ASCIIGenomeHistory current, 
									 final History cmdHistory, 
									 final TrackSet trackSet,
		                             final GenomicCoordsHistory gch 
		                             ){

	Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {
		public void run() {

		ASCIIGenomeHistory newYamlHistory= null;
		try {
			newYamlHistory = new ASCIIGenomeHistory(null);
		} catch (IOException e1) {
			e1.printStackTrace();
		} 
		try{
			// List of commands
			ListIterator<Entry> iter = cmdHistory.entries();
			List<String>lastCommands= new ArrayList<String>();
			int max_cmds= 2000; // Maximum number of commands to write out to asciigenomo_history.
			while(iter.hasNext()){
				if(max_cmds == 0){
					break;
				}
				max_cmds--;
				lastCommands.add(iter.next().value().toString());
			}
			newYamlHistory.setCommands(lastCommands);
			
			// List of files
			List<String> opened= new ArrayList<String>();
			for(String f : trackSet.getOpenedFiles()){
				if(new File(f).getName().startsWith(".asciigenome.")){
					continue;
				}
				opened.add(f);
			}						
			List<String>lastFiles= new ArrayList<String>(opened);
			int max_files= 200; // Maximum number of files to write out to asciigenomo_history.
			lastFiles= lastFiles.subList(Math.max(0, lastFiles.size() - max_files), lastFiles.size());
			newYamlHistory.setFiles(lastFiles);
			
			// Positions
			List<String> lastPos= gch.prepareHistoryForHistoryFile(newYamlHistory.getFileName(), 100);
			newYamlHistory.setPositions(lastPos);

			// Fasta ref
			if(gch.current().getFastaFile() != null && ! gch.current().getFastaFile().trim().isEmpty()){
				String fasta= new File(gch.current().getFastaFile()).getAbsolutePath();
				List<String> ff= Arrays.asList(new String[] {fasta});
				newYamlHistory.setReference(ff);					
			} else {
				newYamlHistory.setReference(current.getReference());
			}
			
			// Write yaml
			newYamlHistory.write();
			
		} catch (Exception e) {
			e.printStackTrace();
				System.err.println("Unable to write history to " + newYamlHistory.getFileName());
			}
		}
    }, "Shutdown-thread"));
}
 
开发者ID:dariober,项目名称:ASCIIGenome,代码行数:68,代码来源:Main.java


注:本文中的jline.console.history.History类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。