Package jline
Class History
- java.lang.Object
-
- jline.History
-
public class History extends java.lang.ObjectA command history buffer.- Author:
- Marc Prud'hommeaux
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddToHistory(java.lang.String buffer)Add the specified buffer to the end of the history.voidclear()Clear the history bufferjava.lang.Stringcurrent()Return the content of the current buffer.voidflushBuffer()Flush the entire history buffer to the output PrintWriter.intgetCurrentIndex()Returns the current history index.java.lang.StringgetHistory(int index)Get the history string for the given index.java.util.ListgetHistoryList()Returns an immutable list of the history buffer.intgetMaxSize()Get the maximum size that the history buffer will store.java.io.PrintWritergetOutput()Returns the PrintWriter that is used to store history elements.voidload(java.io.InputStream in)Load the history buffer from the specified InputStream.voidload(java.io.Reader reader)Load the history buffer from the specified Reader.voidmoveToEnd()Move to the end of the history buffer.booleanmoveToFirstEntry()Moves the history index to the first entry.booleanmoveToLastEntry()This 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.intsearchBackwards(java.lang.String s)Search backwards in history from the current position.intsearchBackwards(java.lang.String searchTerm, int startIndex)Search backward in history from a given position.voidsetCurrentIndex(int index)Set current index to given number.voidsetHistoryFile(java.io.File historyFile)voidsetMaxSize(int maxSize)Set the maximum size that the history buffer will store.voidsetOutput(java.io.PrintWriter output)The output to which all history elements will be written (or null of history is not saved to a buffer).intsize()java.lang.StringtoString()Returns the standardAbstractCollection.toString()representation of the history list.
-
-
-
Method Detail
-
setHistoryFile
public void setHistoryFile(java.io.File historyFile) throws java.io.IOException- Throws:
java.io.IOException
-
load
public void load(java.io.InputStream in) throws java.io.IOExceptionLoad the history buffer from the specified InputStream.- Throws:
java.io.IOException
-
load
public void load(java.io.Reader reader) throws java.io.IOExceptionLoad the history buffer from the specified Reader.- Throws:
java.io.IOException
-
size
public int size()
-
clear
public void clear()
Clear the history buffer
-
addToHistory
public void addToHistory(java.lang.String buffer)
Add the specified buffer to the end of the history. The pointer is set to the end of the history buffer.
-
flushBuffer
public void flushBuffer() throws java.io.IOExceptionFlush the entire history buffer to the output PrintWriter.- Throws:
java.io.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
public void setOutput(java.io.PrintWriter output)
The output to which all history elements will be written (or null of history is not saved to a buffer).
-
getOutput
public java.io.PrintWriter getOutput()
Returns the PrintWriter that is used to store history elements.
-
getCurrentIndex
public int getCurrentIndex()
Returns the current history index.
-
current
public java.lang.String 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
public java.util.List getHistoryList()
Returns an immutable list of the history buffer.
-
toString
public java.lang.String toString()
Returns the standardAbstractCollection.toString()representation of the history list.- Overrides:
toStringin classjava.lang.Object
-
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
public int searchBackwards(java.lang.String searchTerm, int startIndex)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
public int searchBackwards(java.lang.String s)
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
public java.lang.String getHistory(int index)
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-
-
-