本文整理了Java中org.jline.reader.History
类的一些代码示例,展示了History
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。History
类的具体详情如下:
包路径:org.jline.reader.History
类名称:History
[英]Console history.
[中]控制台历史记录。
代码示例来源:origin: org.springframework.shell/spring-shell-core
@EventListener
public void onContextClosedEvent(ContextClosedEvent event) throws IOException {
history.save();
}
}
代码示例来源:origin: julianhyde/sqlline
private String calculateCommand(int currentOffset, Set<Integer> offsets) {
if (!offsets.add(currentOffset)) {
throw new IllegalArgumentException(
"Cycled rerun of commands from history " + offsets);
}
History history = sqlLine.getLineReader().getHistory();
Iterator<History.Entry> iterator = currentOffset > 0
? history.iterator(currentOffset - 1)
: history.reverseIterator(history.size() - 1 + currentOffset);
String command = iterator.next().line();
if (command.trim().startsWith("!/") || command.startsWith("!rerun")) {
String[] cmd = sqlLine.split(command);
if (cmd.length > 2 || (cmd.length == 2 && !cmd[1].matches("-?\\d+"))) {
return command;
}
int offset = cmd.length == 1 ? -1 : Integer.parseInt(cmd[1]);
if (history.size() < offset || history.size() - 1 < -offset) {
return command;
}
return calculateCommand(offset, offsets);
}
return command;
}
代码示例来源:origin: apache/karaf
@Override
public void clear() {
try {
history.purge();
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}
代码示例来源:origin: org.jline/jline
default ListIterator<Entry> iterator() {
return iterator(first());
}
代码示例来源:origin: org.springframework.shell/spring-shell-standard-commands
@ShellMethod(value = "Display or save the history of previously run commands")
public List<String> history(@ShellOption(help = "A file to save history to.", defaultValue = ShellOption.NULL) File file) throws IOException {
if (file == null) {
List<String> result = new ArrayList<>(jLineHistory.size());
jLineHistory.forEach(e -> result.add(e.line()));
return result;
} else {
try (FileWriter w = new FileWriter(file)) {
for (org.jline.reader.History.Entry entry : jLineHistory) {
w.append(entry.line()).append(System.lineSeparator());
}
}
return Collections.singletonList(String.format("Wrote %d entries to %s", jLineHistory.size(), file));
}
}
}
代码示例来源:origin: org.jline/jline
history.purge();
history.save();
代码示例来源:origin: julianhyde/sqlline
public void setHistoryFile(String historyFile) {
final String currentValue = get(HISTORY_FILE);
if (Objects.equals(currentValue, historyFile)
|| Objects.equals(currentValue, Commands.expand(historyFile))) {
return;
}
if (DEFAULT.equalsIgnoreCase(historyFile)) {
set(HISTORY_FILE, DEFAULT);
} else {
propertiesMap.put(HISTORY_FILE, Commands.expand(historyFile));
}
if (sqlLine != null && sqlLine.getLineReader() != null) {
History history = sqlLine.getLineReader().getHistory();
if (history == null) {
history = new DefaultHistory();
} else {
try {
history.save();
} catch (IOException e) {
sqlLine.handleException(e);
}
}
sqlLine.getLineReader()
.setVariable(LineReader.HISTORY_FILE, get(HISTORY_FILE));
history.attach(sqlLine.getLineReader());
}
}
代码示例来源:origin: org.jline/jline
protected boolean doSearchHistory(boolean backward) {
if (history.isEmpty()) {
return false;
history.moveTo(searchIndex);
if (pair == null) {
pair = StreamSupport.stream(
Spliterators.spliteratorUnknownSize(history.reverseIterator(searchIndex < 0 ? history.last() : searchIndex - 1), Spliterator.ORDERED), false)
.flatMap(e -> matches(pat, e.line(), e.index()).stream())
.findFirst()
if (pair == null) {
pair = StreamSupport.stream(
Spliterators.spliteratorUnknownSize(history.iterator((searchIndex < 0 ? history.last() : searchIndex) + 1), Spliterator.ORDERED), false)
.flatMap(e -> matches(pat, e.line(), e.index()).stream())
.findFirst()
buf.clear();
if (searchIndex >= 0) {
buf.write(history.get(searchIndex));
} else {
buf.write(originalBuffer.toString());
代码示例来源:origin: org.jline/jline
default boolean isEmpty() {
return size() == 0;
}
代码示例来源:origin: org.jline/jline
switch (c) {
case '!':
if (history.size() == 0) {
throw new IllegalArgumentException("!!: event not found");
rep = history.get(history.index() - 1);
break;
case '#':
idx = searchBackwards(history, sc, history.index(), false);
if (idx < 0) {
throw new IllegalArgumentException("!?" + sc + ": event not found");
} else {
rep = history.get(idx);
if (history.size() == 0) {
throw new IllegalArgumentException("!$: event not found");
String previous = history.get(history.index() - 1).trim();
int lastSpace = previous.lastIndexOf(' ');
if (lastSpace != -1) {
if (neg && idx > 0 && idx <= history.size()) {
rep = history.get(history.index() - idx);
} else if (!neg && idx > history.index() - history.size() && idx <= history.index()) {
rep = history.get(idx - 1);
} else {
throw new IllegalArgumentException((neg ? "!-" : "!") + line.substring(i1, i) + ": event not found");
代码示例来源:origin: org.jline/jline
default Iterator<Entry> reverseIterator(int index) {
return new Iterator<Entry>() {
private final ListIterator<Entry> it = iterator(index + 1);
@Override
public boolean hasNext() {
return it.hasPrevious();
}
@Override
public Entry next() {
return it.previous();
}
};
}
代码示例来源:origin: org.jline/jline
public int searchForwards(String searchTerm, int startIndex, boolean startsWith) {
boolean caseInsensitive = isSet(Option.CASE_INSENSITIVE_SEARCH);
if (caseInsensitive) {
searchTerm = searchTerm.toLowerCase();
}
if (startIndex > history.last()) {
startIndex = history.last();
}
ListIterator<History.Entry> it = history.iterator(startIndex);
if (searchIndex != -1 && it.hasNext()) {
it.next();
}
while (it.hasNext()) {
History.Entry e = it.next();
String line = e.line();
if (caseInsensitive) {
line = line.toLowerCase();
}
int idx = line.indexOf(searchTerm);
if ((startsWith && idx == 0) || (!startsWith && idx >= 0)) {
return e.index();
}
}
return -1;
}
代码示例来源:origin: org.jline/jline
protected boolean viRepeatSearch() {
if (searchDir == 0) {
return false;
}
int si = searchDir < 0
? searchBackwards(searchString, searchIndex, false)
: searchForwards(searchString, searchIndex, false);
if (si == -1 || si == history.index()) {
return false;
}
searchIndex = si;
/*
* Show the match.
*/
buf.clear();
history.moveTo(searchIndex);
buf.write(history.get(searchIndex));
if (VICMD.equals(keyMap)) {
buf.move(-1);
}
return true;
}
代码示例来源:origin: org.jline/jline
history.attach(this);
代码示例来源:origin: apache/karaf
@Override
public CharSequence get(int index) {
return history.get(index - 1);
}
}
代码示例来源:origin: org.jline/jline-builtins
history.purge();
history.save();
代码示例来源:origin: apache/karaf
public int last() {
return first() + history.size() - 1;
}
代码示例来源:origin: apache/karaf
public int first() {
return history.iterator().next().index() + 1;
}
代码示例来源:origin: sqlline/sqlline
fileHistory.attach(lineReader);
setLineReader(lineReader);
return lineReader;
代码示例来源:origin: org.apache.karaf.shell/org.apache.karaf.shell.core
@Override
public CharSequence get(int index) {
return history.get(index - 1);
}
}
内容来源于网络,如有侵权,请联系作者删除!