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 class
private static class
Nested classes/interfaces inherited from interface org.jline.reader.History
History.Entry
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final int
static final int
private Map
<String, DefaultHistory.HistoryFileData> private int
private final LinkedList
<History.Entry> private int
private LineReader
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
protected void
addHistoryLine
(Path path, String line) protected void
addHistoryLine
(Path path, String line, boolean checkDuplicates) void
Append history to the file.void
attach
(LineReader reader) Initialize the history for the given reader.protected DefaultHistory.EntryImpl
createEntry
(int index, Instant time, String line) Create a history entry.current()
Return the content of the current buffer.private String
doHistoryFileDataKey
(Path path) (package private) static List
<History.Entry> doTrimHistory
(List<History.Entry> allItems, int max) private static String
int
first()
private String
format
(History.Entry entry) get
(int index) private int
getEntriesInFile
(Path path) private DefaultHistory.HistoryFileData
getHistoryFileData
(Path path) private int
getLastLoaded
(Path path) private Path
getPath()
private void
incEntriesInFile
(Path path, int amount) int
index()
protected void
internalAdd
(Instant time, String line) protected void
internalAdd
(Instant time, String line, boolean checkDuplicates) private void
private void
internalWrite
(Path path, int from) boolean
isEmpty()
private boolean
isLineReaderHistory
(Path path) iterator
(int index) int
last()
void
load()
Load history.protected boolean
matchPatterns
(String patterns, String line) private void
boolean
moveTo
(int index) Move to the specified index in the historyvoid
Move to the end of the history buffer.boolean
Moves the history index to the first entry.boolean
This moves the history to the last entry.boolean
next()
Move the pointer to the next element in the buffer.boolean
previous()
Move the pointer to the previous element in the buffer.void
purge()
Purge history.void
Read history from the file.void
Reset index after removevoid
save()
Save history.private void
setEntriesInFile
(Path path, int entriesInFile) private void
setHistoryFileData
(Path path, DefaultHistory.HistoryFileData historyFileData) private void
setLastLoaded
(Path path, int lastloaded) int
size()
toString()
protected void
trimHistory
(Path path, int max) (package private) static String
void
Write history to the file.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods 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:History
Initialize the history for the given reader. -
load
Description copied from interface:History
Load history.- Specified by:
load
in interfaceHistory
- Throws:
IOException
- if a problem occurs
-
read
Description copied from interface:History
Read history from the file. If checkDuplicates istrue
only the events that are not contained within the internal list are added.- Specified by:
read
in 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:History
Purge history.- Specified by:
purge
in interfaceHistory
- Throws:
IOException
- if a problem occurs
-
write
Description copied from interface:History
Write history to the file. If incremental only the events that are new since the last incremental operation to the file are added.- Specified by:
write
in interfaceHistory
- Parameters:
file
- History fileincremental
- If true incremental write operation is performed.- Throws:
IOException
- if a problem occurs
-
append
Description copied from interface:History
Append history to the file. If incremental only the events that are new since the last incremental operation to the file are added.- Specified by:
append
in interfaceHistory
- Parameters:
file
- History fileincremental
- If true incremental append operation is performed.- Throws:
IOException
- if a problem occurs
-
save
Description copied from interface:History
Save history.- Specified by:
save
in 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:
spliterator
in interfaceIterable<History.Entry>
-
resetIndex
public void resetIndex()Description copied from interface:History
Reset index after remove- Specified by:
resetIndex
in interfaceHistory
-
moveToLast
public boolean moveToLast()This moves the history to the last entry. This entry is one position before the moveToEnd() position.- Specified by:
moveToLast
in 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:
moveToFirst
in 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
-