本文整理汇总了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;
}
示例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;
}
示例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();
}
}
示例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;
}
};
}
示例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();
}
示例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;
}
示例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());
}
示例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);
}
}
示例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();
}
示例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));
}
示例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);
}
示例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();
}
示例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();
}
}));
}
示例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();
}
});
}
示例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"));
}