Package jline
Class History
java.lang.Object
jline.History
A command history buffer.
- Author:
- Marc Prud'hommeaux
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
addToHistory
(String buffer) Add the specified buffer to the end of the history.void
clear()
Clear the history buffercurrent()
Return the content of the current buffer.void
Flush the entire history buffer to the output PrintWriter.int
Returns the current history index.getHistory
(int index) Get the history string for the given index.Returns an immutable list of the history buffer.int
Get the maximum size that the history buffer will store.Returns the PrintWriter that is used to store history elements.void
load
(InputStream in) Load the history buffer from the specified InputStream.void
Load the history buffer from the specified Reader.void
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.int
Search backwards in history from the current position.int
searchBackwards
(String searchTerm, int startIndex) Search backward in history from a given position.void
setCurrentIndex
(int index) Set current index to given number.void
setHistoryFile
(File historyFile) void
setMaxSize
(int maxSize) Set the maximum size that the history buffer will store.void
setOutput
(PrintWriter output) The output to which all history elements will be written (or null of history is not saved to a buffer).int
size()
toString()
Returns the standardAbstractCollection.toString()
representation of the history list.
-
Constructor Details
-
History
public History()Construstor: initialize a blank history. -
History
Construstor: initialize History object the the specifiedFile
for storage.- Throws:
IOException
-
-
Method Details
-
setHistoryFile
- Throws:
IOException
-
load
Load the history buffer from the specified InputStream.- Throws:
IOException
-
load
Load the history buffer from the specified Reader.- Throws:
IOException
-
size
public int size() -
clear
public void clear()Clear the history buffer -
addToHistory
Add the specified buffer to the end of the history. The pointer is set to the end of the history buffer. -
flushBuffer
Flush the entire history buffer to the output PrintWriter.- Throws:
IOException
-
moveToLastEntry
public boolean moveToLastEntry()This moves the history to the last entry. This entry is one position before the moveToEnd() position.- Returns:
- Returns false if there were no history entries or the history index was already at the last entry.
-
moveToEnd
public void moveToEnd()Move to the end of the history buffer. This will be a blank entry, after all of the other entries. -
setMaxSize
public void setMaxSize(int maxSize) Set the maximum size that the history buffer will store. -
getMaxSize
public int getMaxSize()Get the maximum size that the history buffer will store. -
setOutput
The output to which all history elements will be written (or null of history is not saved to a buffer). -
getOutput
Returns the PrintWriter that is used to store history elements. -
getCurrentIndex
public int getCurrentIndex()Returns the current history index. -
current
Return the content of the current buffer. -
previous
public boolean previous()Move the pointer to the previous element in the buffer.- Returns:
- true if we successfully went to the previous element
-
next
public boolean next()Move the pointer to the next element in the buffer.- Returns:
- true if we successfully went to the next element
-
getHistoryList
Returns an immutable list of the history buffer. -
toString
Returns the standardAbstractCollection.toString()
representation of the history list. -
moveToFirstEntry
public boolean moveToFirstEntry()Moves the history index to the first entry.- Returns:
- Return false if there are no entries in the history or if the history is already at the beginning.
-
searchBackwards
Search backward in history from a given position.- Parameters:
searchTerm
- substring to search for.startIndex
- the index from which on to search- Returns:
- index where this substring has been found, or -1 else.
-
searchBackwards
Search backwards in history from the current position.- Parameters:
searchTerm
- substring to search for.- Returns:
- index where the substring has been found, or -1 else.
-
getHistory
Get the history string for the given index.- Parameters:
index
-- Returns:
-
setCurrentIndex
public void setCurrentIndex(int index) Set current index to given number.- Parameters:
index
-
-