Package org.jline.reader.impl.history
Class DefaultHistory
java.lang.Object
org.jline.reader.impl.history.DefaultHistory
- All Implemented Interfaces:
Iterable<History.Entry>,History
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected static classprivate static classNested classes/interfaces inherited from interface org.jline.reader.History
History.Entry -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intstatic final intprivate Map<String, DefaultHistory.HistoryFileData> private intprivate final LinkedList<History.Entry> private intprivate LineReader -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidprotected voidaddHistoryLine(Path path, String line) protected voidaddHistoryLine(Path path, String line, boolean checkDuplicates) voidAppend history to the file.voidattach(LineReader reader) Initialize the history for the given reader.protected DefaultHistory.EntryImplcreateEntry(int index, Instant time, String line) Create a history entry.current()Return the content of the current buffer.private StringdoHistoryFileDataKey(Path path) (package private) static List<History.Entry> doTrimHistory(List<History.Entry> allItems, int max) private static Stringintfirst()private Stringformat(History.Entry entry) get(int index) private intgetEntriesInFile(Path path) private DefaultHistory.HistoryFileDatagetHistoryFileData(Path path) private intgetLastLoaded(Path path) private PathgetPath()private voidincEntriesInFile(Path path, int amount) intindex()protected voidinternalAdd(Instant time, String line) protected voidinternalAdd(Instant time, String line, boolean checkDuplicates) private voidprivate voidinternalWrite(Path path, int from) booleanisEmpty()private booleanisLineReaderHistory(Path path) iterator(int index) intlast()voidload()Load history.protected booleanmatchPatterns(String patterns, String line) private voidbooleanmoveTo(int index) Move to the specified index in the historyvoidMove to the end of the history buffer.booleanMoves the history index to the first entry.booleanThis moves the history to the last entry.booleannext()Move the pointer to the next element in the buffer.booleanprevious()Move the pointer to the previous element in the buffer.voidpurge()Purge history.voidRead history from the file.voidReset index after removevoidsave()Save history.private voidsetEntriesInFile(Path path, int entriesInFile) private voidsetHistoryFileData(Path path, DefaultHistory.HistoryFileData historyFileData) private voidsetLastLoaded(Path path, int lastloaded) intsize()toString()protected voidtrimHistory(Path path, int max) (package private) static StringvoidWrite history to the file.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface org.jline.reader.History
add, isPersistable, iterator, reverseIterator, reverseIterator
-
Field Details
-
DEFAULT_HISTORY_SIZE
public static final int DEFAULT_HISTORY_SIZE- See Also:
-
DEFAULT_HISTORY_FILE_SIZE
public static final int DEFAULT_HISTORY_FILE_SIZE- See Also:
-
items
-
reader
-
historyFiles
-
offset
private int offset -
index
private int index
-
-
Constructor Details
-
DefaultHistory
public DefaultHistory() -
DefaultHistory
-
-
Method Details
-
getPath
-
attach
Description copied from interface:HistoryInitialize the history for the given reader. -
load
Description copied from interface:HistoryLoad history.- Specified by:
loadin interfaceHistory- Throws:
IOException- if a problem occurs
-
read
Description copied from interface:HistoryRead history from the file. If checkDuplicates istrueonly the events that are not contained within the internal list are added.- Specified by:
readin interfaceHistory- Parameters:
file- History filecheckDuplicates- Iftrue, duplicate history entries will be discarded- Throws:
IOException- if a problem occurs
-
doHistoryFileDataKey
-
getHistoryFileData
-
setHistoryFileData
-
isLineReaderHistory
- Throws:
IOException
-
setLastLoaded
-
setEntriesInFile
-
incEntriesInFile
-
getLastLoaded
-
getEntriesInFile
-
addHistoryLine
-
addHistoryLine
-
purge
Description copied from interface:HistoryPurge history.- Specified by:
purgein interfaceHistory- Throws:
IOException- if a problem occurs
-
write
Description copied from interface:HistoryWrite history to the file. If incremental only the events that are new since the last incremental operation to the file are added.- Specified by:
writein interfaceHistory- Parameters:
file- History fileincremental- If true incremental write operation is performed.- Throws:
IOException- if a problem occurs
-
append
Description copied from interface:HistoryAppend history to the file. If incremental only the events that are new since the last incremental operation to the file are added.- Specified by:
appendin interfaceHistory- Parameters:
file- History fileincremental- If true incremental append operation is performed.- Throws:
IOException- if a problem occurs
-
save
Description copied from interface:HistorySave history.- Specified by:
savein interfaceHistory- Throws:
IOException- if a problem occurs
-
internalWrite
- Throws:
IOException
-
trimHistory
- Throws:
IOException
-
createEntry
Create a history entry. Subclasses may override to use their own entry implementations.- Parameters:
index- index of history entrytime- entry creation timeline- the entry text- Returns:
- entry object
-
internalClear
private void internalClear() -
doTrimHistory
-
size
public int size() -
isEmpty
public boolean isEmpty() -
index
public int index() -
first
public int first() -
last
public int last() -
format
-
get
-
add
-
matchPatterns
-
internalAdd
-
internalAdd
-
maybeResize
private void maybeResize() -
iterator
-
spliterator
- Specified by:
spliteratorin interfaceIterable<History.Entry>
-
resetIndex
public void resetIndex()Description copied from interface:HistoryReset index after remove- Specified by:
resetIndexin interfaceHistory
-
moveToLast
public boolean moveToLast()This moves the history to the last entry. This entry is one position before the moveToEnd() position.- Specified by:
moveToLastin interfaceHistory- Returns:
- Returns false if there were no history iterator or the history index was already at the last entry.
-
moveTo
public boolean moveTo(int index) Move to the specified index in the history -
moveToFirst
public boolean moveToFirst()Moves the history index to the first entry.- Specified by:
moveToFirstin interfaceHistory- Returns:
- Return false if there are no iterator in the history or if the history is already at the beginning.
-
moveToEnd
public void moveToEnd()Move to the end of the history buffer. This will be a blank entry, after all of the other iterator. -
current
Return the content of the current buffer. -
previous
public boolean previous()Move the pointer to the previous element in the buffer. -
next
public boolean next()Move the pointer to the next element in the buffer. -
toString
-
escape
-
unescape
-