Class InMemoryHistory
java.lang.Object
org.aesh.readline.history.History
org.aesh.readline.history.InMemoryHistory
- Direct Known Subclasses:
FileHistory
A simple in-memory history implementation
By default max size is 500
- Author:
- Ståle W. Pedersen
-
Constructor Summary
ConstructorsConstructorDescriptionCreates an InMemoryHistory with the default maximum size of 500 entries.InMemoryHistory(int maxSize) Creates an InMemoryHistory with the specified maximum size. -
Method Summary
Modifier and TypeMethodDescriptionvoidclear()Clears all entries from the history.int[]find(int[] search) Finds an entry in the history that matches the search.int[]get(int index) Gets the history entry at the specified index.List<int[]> getAll()Gets all entries in the history.int[]Gets the current line being edited.Gets the current search direction.Gets the timestamps (epoch millis) for all entries in the history.Optional<int[]> Fetch the next history entry.Optional<int[]> Fetch the previous history entry.voidpush(int[] entry) Pushes a new entry to the history.protected voidpushWithTimestamp(int[] entry, long timestamp) Push an entry with a specific timestamp.int[]search(int[] search) Searches for an entry in the history that contains the search pattern.voidsetCurrent(int[] line) Sets the current line being edited (used for history navigation).voidsetSearchDirection(SearchDirection direction) Sets the search direction for history searches.intsize()Returns the number of entries in the history.voidstop()Stops the history and performs any necessary cleanup (e.g., saving to file).Methods inherited from class History
disable, enable, getIgnorePatterns, isEnabled, setIgnorePatterns, shouldIgnore
-
Constructor Details
-
InMemoryHistory
public InMemoryHistory()Creates an InMemoryHistory with the default maximum size of 500 entries. -
InMemoryHistory
public InMemoryHistory(int maxSize) Creates an InMemoryHistory with the specified maximum size.- Parameters:
maxSize- the maximum number of history entries, or -1 for unlimited
-
-
Method Details
-
push
-
pushWithTimestamp
protected void pushWithTimestamp(int[] entry, long timestamp) Push an entry with a specific timestamp. Used by FileHistory to restore timestamps from the history file.- Parameters:
entry- the history entrytimestamp- the timestamp in epoch milliseconds
-
find
-
get
-
size
-
setSearchDirection
Description copied from class:HistorySets the search direction for history searches.- Specified by:
setSearchDirectionin classHistory- Parameters:
direction- the search direction
-
getSearchDirection
Description copied from class:HistoryGets the current search direction.- Specified by:
getSearchDirectionin classHistory- Returns:
- the current search direction
-
previousFetch
Description copied from class:HistoryFetch the previous history entry.- Specified by:
previousFetchin classHistory- Returns:
- an Optional containing the previous history entry, or empty if at the start
-
nextFetch
-
search
-
setCurrent
public void setCurrent(int[] line) Description copied from class:HistorySets the current line being edited (used for history navigation).- Specified by:
setCurrentin classHistory- Parameters:
line- the current line
-
getCurrent
public int[] getCurrent()Description copied from class:HistoryGets the current line being edited.- Specified by:
getCurrentin classHistory- Returns:
- the current line
-
getAll
-
getTimestamps
Description copied from class:HistoryGets the timestamps (epoch millis) for all entries in the history. The returned list is parallel toHistory.getAll()— same size and order.The default implementation returns null, indicating timestamps are not available.
- Overrides:
getTimestampsin classHistory- Returns:
- a list of timestamps, or null if timestamps are not tracked
-
clear
-
stop
-