|
The Java-Readline Library, Version 0.8.0 | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.gnu.readline.Readline
This class implements basic functionality of the GNU-readline interface. It uses native method calls if available, otherwise it defaults to normal I/O using a BufferedReader.
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
| Constructor Summary | |
Readline()
|
|
| Method Summary | |
static void |
addToHistory(java.lang.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 java.lang.String |
getEncoding()
Query current encoding of fallback BufferedReader. |
static void |
getHistory(java.util.Collection collection)
Get the history buffer in a supplied Collection. |
static java.lang.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 java.lang.String |
getLineBuffer()
Query the current line buffer. |
static boolean |
getThrowExceptionOnUnsupportedMethod()
Query behavior in case an unsupported method is called. |
static java.lang.String |
getWordBreakCharacters()
Query word break characters. |
static boolean |
hasTerminal()
Return if we have a terminal. |
static void |
initReadline(java.lang.String applicationName)
Initialize the GNU-Readline library. |
static void |
load(ReadlineLibrary lib)
Load an implementing backing library. |
static boolean |
parseAndBind(java.lang.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(java.lang.String filename)
Reads a history file into memory |
static void |
readInitFile(java.lang.String filename)
Read keybindings and variable assignments from a file. |
static java.lang.String |
readline(java.lang.String prompt)
Display a prompt on standard output and read a string from standard input. |
static java.lang.String |
readline(java.lang.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(java.lang.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(java.lang.String wordBreakCharacters)
Set word break characters. |
static void |
writeHistoryFile(java.lang.String filename)
Writes a history file to disc |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
public Readline()
| Method Detail |
public static final void load(ReadlineLibrary lib)
throws java.lang.UnsatisfiedLinkError
lib - An object (constant) of type ReadlineLibrary
java.lang.UnsatisfiedLinkError - if the shared library could not be
found. Add it to your LD_LIBRARY_PATH.ReadlineLibrarypublic static void initReadline(java.lang.String applicationName)
Supporting implementations:
applicationName - Name of application in initialization file
public static java.lang.String readline(java.lang.String prompt)
throws java.io.EOFException,
java.io.IOException,
java.io.UnsupportedEncodingException
Supporting implementations:
prompt - Prompt to display
java.io.EOFException - on end-of-file, i.e. CTRL-d input.
java.io.IOException
java.io.UnsupportedEncodingExceptionreadline(String,boolean),
#addHistory()
public static java.lang.String readline(java.lang.String prompt,
boolean addToHist)
throws java.io.EOFException,
java.io.IOException,
java.io.UnsupportedEncodingException
prompt - Prompt to displayaddToHist - 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().)
java.io.EOFException - on end-of-file, i.e. CTRL-d input.
java.io.IOException
java.io.UnsupportedEncodingExceptionreadline(String),
#addHistory()public static void addToHistory(java.lang.String line)
Supporting implementations:
line - The line to add to the history
UnsupportOperationException - if underlying library doesn't support
a historypublic static void getHistory(java.util.Collection collection)
Supporting implementations:
collection - where to store the history
UnsupportOperationException - if underlying library doesn't support
a historypublic static int getHistorySize()
Supporting implementations:
public static void clearHistory()
Supporting implementations:
public static java.lang.String getHistoryLine(int i)
Supporting implementations:
i - the index of the entry to return
java.lang.ArrayIndexOutOfBoundsException - index out of range
public static void readInitFile(java.lang.String filename)
throws java.io.IOException
Supporting implementations:
filename - Name of file to read bindings from
java.io.IOExceptionpublic static boolean parseAndBind(java.lang.String line)
Supporting implementations:
line - Simulated line from inputrc file
public static void readHistoryFile(java.lang.String filename)
throws java.io.EOFException,
java.io.UnsupportedEncodingException
Supporting implementations:
filename - Name of history file to read
java.io.EOFException
java.io.UnsupportedEncodingException
public static void writeHistoryFile(java.lang.String filename)
throws java.io.EOFException,
java.io.UnsupportedEncodingException
Supporting implementations:
filename - Name of history file to write
java.io.EOFException
java.io.UnsupportedEncodingExceptionpublic static void setCompleter(ReadlineCompleter rlc)
null
will result in the default behaviour of readline which is filename
completion.
Supporting implementations:
rlc - An object implementing the ReadlineCompleter interfacepublic static ReadlineCompleter getCompleter()
public static void cleanup()
Supporting implementations:
public static boolean hasTerminal()
load(ReadlineLibrary)())
first, otherwise this will always return true.
Supporting implementations:
public static java.lang.String getWordBreakCharacters()
Supporting implementations:
public static java.lang.String getLineBuffer()
ReadlineCompleter implementation to access the full text
given so far.
Supporting implementations:
public static void setWordBreakCharacters(java.lang.String wordBreakCharacters)
throws java.io.UnsupportedEncodingException
Supporting implementations:
wordBreakCharacters - A string of word break characters
java.io.UnsupportedEncodingExceptionpublic static void setThrowExceptionOnUnsupportedMethod(boolean flag)
flag - configuration flagpublic static boolean getThrowExceptionOnUnsupportedMethod()
public static void setEncoding(java.lang.String encoding)
encoding - encoding to usepublic static java.lang.String getEncoding()
|
The Java-Readline Library, Version 0.8.0 | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||