org.gnu.readline
public class Readline extends Object
A typical implementation could look like:
try { Readline.load(ReadlineLibrary.GnuReadline); } catch (UnsatisfiedLinkError ignore_me) { System.err.println("couldn't load readline lib. Using simple stdin."); } Readline.initReadline("myapp"); Runtime.getRuntime() // if your version supports .addShutdownHook(new Thread() { // addShutdownHook (since 1.3) public void run() { Readline.cleanup(); } }); while (true) { try { line = Readline.readline("myprompt> "); if (line == null) System.out.println("no input"); else processLine(); } catch (EOFException e) { break; } catch (Exception e) { doSomething(); } } Readline.cleanup(); // see note above about addShutdownHook
Version: $Revision: 1.27 $
Method Summary | |
---|---|
static void | addToHistory(String line)
Add a line to the in-memory history.
|
static void | cleanup()
Reset the readline library and with it, the terminal.
|
static void | clearHistory()
Clear the history buffer.
|
static ReadlineCompleter | getCompleter()
Query current completer function. |
static String | getEncoding()
Query current encoding of fallback BufferedReader. |
static void | getHistory(Collection collection)
Get the history buffer in a supplied Collection.
|
static String | getHistoryLine(int i)
Get the specified entry from the history buffer. |
static int | getHistorySize()
Get the size, in elements (lines), of the history buffer.
|
static String | getLineBuffer()
Query the current line buffer. |
static boolean | getThrowExceptionOnUnsupportedMethod()
Query behavior in case an unsupported method is called. |
static String | getWordBreakCharacters()
Query word break characters.
|
static boolean | hasTerminal()
Return if we have a terminal. |
static void | initReadline(String applicationName)
Initialize the GNU-Readline library. |
static void | load(ReadlineLibrary lib)
Load an implementing backing library. |
static boolean | parseAndBind(String line)
Parse argument string as if it had been read from `inputrc' file
and perform key bindings and variable assignments found.
|
static void | readHistoryFile(String filename)
Reads a history file into memory
Supporting implementations:
|
static void | readInitFile(String filename)
Read keybindings and variable assignments from a file. |
static String | readline(String prompt)
Display a prompt on standard output and read a string from standard
input. |
static String | readline(String prompt, boolean addToHist)
Display a prompt on standard output and read a string from
standard input. |
static void | setCompleter(ReadlineCompleter rlc)
Set your completer implementation. |
static void | setEncoding(String encoding)
Set current encoding of fallback BufferedReader. |
static void | setThrowExceptionOnUnsupportedMethod(boolean flag)
Configure behavior in case an unsupported method is called. |
static void | setWordBreakCharacters(String wordBreakCharacters)
Set word break characters.
|
static void | writeHistoryFile(String filename)
Writes a history file to disc
Supporting implementations:
|
Supporting implementations:
Parameters: line The line to add to the history
Throws: UnsupportOperationException if underlying library doesn't support a history
Supporting implementations:
Supporting implementations:
Returns: Current ReadlineCompleter object
Returns: current encoding
Supporting implementations:
Parameters: collection where to store the history
Throws: UnsupportOperationException if underlying library doesn't support a history
Supporting implementations:
Parameters: i the index of the entry to return
Returns: the line at the specified index in the history buffer
Throws: ArrayIndexOutOfBoundsException index out of range
Supporting implementations:
Returns: the number of lines in the history buffer
Supporting implementations:
Returns: configuration flag
Supporting implementations:
Supporting implementations:
Supporting implementations:
Parameters: applicationName Name of application in initialization file
Parameters: lib An object (constant) of type ReadlineLibrary
Throws: UnsatisfiedLinkError if the shared library could not be found. Add it to your LD_LIBRARY_PATH.
See Also: ReadlineLibrary
Supporting implementations:
Parameters: line Simulated line from inputrc file
Returns: boolean False in case of error
Supporting implementations:
Parameters: filename Name of history file to read
Supporting implementations:
Parameters: filename Name of file to read bindings from
Returns: void
Supporting implementations:
Parameters: prompt Prompt to display
Returns: The string the user entered or 'null' if there was no input.
Throws: EOFException on end-of-file, i.e. CTRL-d input.
Parameters: prompt Prompt to display addToHist true to add the line to the history automatically; false to refrain from adding the line to the history. (You can manually add the line to the history by calling addHistory().)
Returns: The string the user entered or 'null' if there was no input.
Throws: EOFException on end-of-file, i.e. CTRL-d input.
null
will result in the default behaviour of readline which is filename
completion.
Supporting implementations:
Parameters: rlc An object implementing the ReadlineCompleter interface
Parameters: encoding encoding to use
Parameters: flag configuration flag
Supporting implementations:
Parameters: wordBreakCharacters A string of word break characters
Supporting implementations:
Parameters: filename Name of history file to write