|
|||||||||
| Home >> All >> org >> gnu >> [ readline overview ] | PREV CLASS NEXT CLASS | ||||||||
SUMMARY: JAVADOC | SOURCE | DOWNLOAD | NESTED | FIELD | CONSTR | METHOD |
DETAIL: FIELD | CONSTR | METHOD | ||||||||
org.gnu.readline
Class Readline

java.lang.Objectorg.gnu.readline.Readline
- public class Readline
- extends java.lang.Object
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
- Version:
- $Revision: 1.27 $
| Field Summary | |
private static ReadlineCompleter |
iCompleter
The currently defined ReadlineCompleter. |
private static java.lang.String |
iEncoding
The current encoding of the BufferedReader. |
private static ReadlineLibrary |
iLib
The currently implementing backing library. |
private static java.io.BufferedReader |
iReader
The BufferedReader for the fallback solution. |
private static boolean |
iThrowException
Configuration flag: throw an UnsupportedOperationException, if true. |
| Constructor Summary | |
Readline()
|
|
| Method Summary | |
static void |
addToHistory(java.lang.String line)
Add a line to the in-memory history. |
private static void |
addToHistoryImpl(java.lang.String line)
Native implementation of addToHistory |
static void |
cleanup()
Reset the readline library and with it, the terminal. |
private static void |
cleanupReadlineImpl()
cleanup readline; reset terminal. |
static void |
clearHistory()
Clear the history buffer. |
private static void |
clearHistoryImpl()
Native implementation of clearHistory |
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. |
private static void |
getHistoryImpl(java.util.Collection collection)
Native implementation of getHistory |
static java.lang.String |
getHistoryLine(int i)
Get the specified entry from the history buffer. |
private static java.lang.String |
getHistoryLineImpl(int i)
Native implementation of getHistoryLine |
static int |
getHistorySize()
Get the size, in elements (lines), of the history buffer. |
private static int |
getHistorySizeImpl()
Native implementation of getHistorySize |
static java.lang.String |
getLineBuffer()
Query the current line buffer. |
private static java.lang.String |
getLineBufferImpl()
Native implementation of getLineBuffer() |
static boolean |
getThrowExceptionOnUnsupportedMethod()
Query behavior in case an unsupported method is called. |
static java.lang.String |
getWordBreakCharacters()
Query word break characters. |
private static java.lang.String |
getWordBreakCharactersImpl()
Native implementation of getWordBreakCharacters() |
static boolean |
hasTerminal()
Return if we have a terminal. |
private static boolean |
hasTerminalImpl()
native implementation of isatty(); |
static void |
initReadline(java.lang.String applicationName)
Initialize the GNU-Readline library. |
private static void |
initReadlineImpl(java.lang.String applicationName)
Native implementation of initReadline() |
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. |
private static boolean |
parseAndBindImpl(java.lang.String line)
Native implementation of parseAndBind(String line) |
static void |
readHistoryFile(java.lang.String filename)
Reads a history file into memory |
private static void |
readHistoryFileImpl(java.lang.String filename)
Native implementation of readHistoryFile(String filename) |
static void |
readInitFile(java.lang.String filename)
Read keybindings and variable assignments from a file. |
private static void |
readInitFileImpl(java.lang.String filename)
Native implementation of readInitFile(String filename) |
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. |
private static java.lang.String |
readlineImpl(java.lang.String prompt)
Native implementation of readline() |
static void |
setCompleter(ReadlineCompleter rlc)
Set your completer implementation. |
private static void |
setCompleterImpl(ReadlineCompleter rlc)
Native implementation of setCompleter(ReadlineCompleter rlc) |
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. |
private static void |
setWordBreakCharactersImpl(java.lang.String wordBreakCharacters)
Native implementation of setWordBreakCharacters() |
static void |
writeHistoryFile(java.lang.String filename)
Writes a history file to disc |
private static void |
writeHistoryFileImpl(java.lang.String filename)
Native implementation of writeHistoryFile(String filename) |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
iCompleter
private static ReadlineCompleter iCompleter
- The currently defined ReadlineCompleter.
iLib
private static ReadlineLibrary iLib
- The currently implementing backing library.
iReader
private static java.io.BufferedReader iReader
- The BufferedReader for the fallback solution.
iEncoding
private static java.lang.String iEncoding
- The current encoding of the BufferedReader. The default is the
value of the property readline.encoding. If this
property is unset, the default is null, so the BufferedReader
will use the default encoding.
iThrowException
private static boolean iThrowException
- Configuration flag: throw an UnsupportedOperationException, if true.
This value defaults to false.
| Constructor Detail |
Readline
public Readline()
| Method Detail |
load
public static final void load(ReadlineLibrary lib) throws java.lang.UnsatisfiedLinkError
- Load an implementing backing library. This method might throw an
UnsatisfiedLinkError in case the native libary is not found in the
library path. If you want to have portable program, just catch and
ignore that error. JavaReadline will then just use the pure Java fallback
solution.
initReadline
public static void initReadline(java.lang.String applicationName)
- Initialize the GNU-Readline library. This will also set the
application name, which can be used in the initialization files of
Readline (usually /etc/inputrc and ~/.inputrc) to define application
specific keys. See the file ReadlineTest.java int the test subdir of
the distribution for an example.
Supporting implementations:
- GNU-Readline
- Editline
- Getline
readline
public static java.lang.String readline(java.lang.String prompt) throws java.io.EOFException, java.io.IOException, java.io.UnsupportedEncodingException
- Display a prompt on standard output and read a string from standard
input. This method returns 'null', if there has been an empty input
(user pressed just [RETURN]) and throws an EOFException on end-of-file
(C-d). This versino of readline() automatically adds the line
to the in-memory history; use the other version of readline()
if you want explicit control over that feature.
Supporting implementations:
- GNU-Readline
- Editline
- Getline
- PureJava
readline
public static java.lang.String readline(java.lang.String prompt, boolean addToHist) throws java.io.EOFException, java.io.IOException, java.io.UnsupportedEncodingException
- Display a prompt on standard output and read a string from
standard input. This method returns 'null', if there has
been an empty input (user pressed just [RETURN]) and throws
an EOFException on end-of-file (C-d).
addToHistory
public static void addToHistory(java.lang.String line)
- Add a line to the in-memory history.
Supporting implementations:
- GNU-Readline
- Editline
- Getline
getHistory
public static void getHistory(java.util.Collection collection)
- Get the history buffer in a supplied Collection.
Supporting implementations:
- GNU-Readline
- Editline
getHistorySize
public static int getHistorySize()
- Get the size, in elements (lines), of the history buffer.
Supporting implementations:
- GNU-Readline
- Editline
clearHistory
public static void clearHistory()
- Clear the history buffer.
Supporting implementations:
- GNU-Readline
- Editline
getHistoryLine
public static java.lang.String getHistoryLine(int i)
- Get the specified entry from the history buffer. History buffer entries
are numbered from 0 through (getHistorySize() - 1), with the
oldest entry at index 0.
Supporting implementations:
- GNU-Readline
- Editline
readInitFile
public static void readInitFile(java.lang.String filename) throws java.io.IOException
- Read keybindings and variable assignments from a file. This method is a
wrapper to rl_read_init_file(char *filename). Throws IOException if
something goes wrong.
Supporting implementations:
- GNU-Readline
parseAndBind
public 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.
Supporting implementations:
- GNU-Readline
readHistoryFile
public static void readHistoryFile(java.lang.String filename) throws java.io.EOFException, java.io.UnsupportedEncodingException
- Reads a history file into memory
Supporting implementations:
- GNU-Readline
- Editline
writeHistoryFile
public static void writeHistoryFile(java.lang.String filename) throws java.io.EOFException, java.io.UnsupportedEncodingException
- Writes a history file to disc
Supporting implementations:
- GNU-Readline
- Editline
setCompleter
public static void setCompleter(ReadlineCompleter rlc)
- Set your completer implementation. Setting this to
nullwill result in the default behaviour of readline which is filename completion.Supporting implementations:
- GNU-Readline
- Editline
getCompleter
public static ReadlineCompleter getCompleter()
- Query current completer function.
cleanup
public static void cleanup()
- Reset the readline library and with it, the terminal.
Supporting implementations:
- GNU-Readline
- Editline
hasTerminal
public static boolean hasTerminal()
- Return if we have a terminal. This requires, that any of the native
libraries have been loaded yet
(so call Readline.
load(ReadlineLibrary)55 ()) first, otherwise this will always return true.Supporting implementations:
- GNU-Readline
- Editline
getWordBreakCharacters
public static java.lang.String getWordBreakCharacters()
- Query word break characters.
Supporting implementations:
- GNU-Readline
- Editline
getLineBuffer
public static java.lang.String getLineBuffer()
- Query the current line buffer. This returns the current content of
the internal line buffer. You might need this in a
ReadlineCompleter implementation to access the full text
given so far.
Supporting implementations:
- GNU-Readline
- Editline
setWordBreakCharacters
public static void setWordBreakCharacters(java.lang.String wordBreakCharacters) throws java.io.UnsupportedEncodingException
- Set word break characters.
Supporting implementations:
- GNU-Readline
- Editline
setThrowExceptionOnUnsupportedMethod
public static void setThrowExceptionOnUnsupportedMethod(boolean flag)
- Configure behavior in case an unsupported method is called. If argument
is true, unsupported methods throw an UnsupportedOperationException.
getThrowExceptionOnUnsupportedMethod
public static boolean getThrowExceptionOnUnsupportedMethod()
- Query behavior in case an unsupported method is called.
setEncoding
public static void setEncoding(java.lang.String encoding)
- Set current encoding of fallback BufferedReader.
getEncoding
public static java.lang.String getEncoding()
- Query current encoding of fallback BufferedReader.
initReadlineImpl
private static void initReadlineImpl(java.lang.String applicationName)
- Native implementation of initReadline()
cleanupReadlineImpl
private static void cleanupReadlineImpl()
- cleanup readline; reset terminal.
hasTerminalImpl
private static boolean hasTerminalImpl()
- native implementation of isatty();
readlineImpl
private static java.lang.String readlineImpl(java.lang.String prompt) throws java.io.EOFException, java.io.UnsupportedEncodingException
- Native implementation of readline()
addToHistoryImpl
private static void addToHistoryImpl(java.lang.String line)
- Native implementation of addToHistory
getHistoryImpl
private static void getHistoryImpl(java.util.Collection collection)
- Native implementation of getHistory
getHistorySizeImpl
private static int getHistorySizeImpl()
- Native implementation of getHistorySize
getHistoryLineImpl
private static java.lang.String getHistoryLineImpl(int i)
- Native implementation of getHistoryLine
clearHistoryImpl
private static void clearHistoryImpl()
- Native implementation of clearHistory
readInitFileImpl
private static void readInitFileImpl(java.lang.String filename) throws java.io.IOException
- Native implementation of readInitFile(String filename)
getLineBufferImpl
private static java.lang.String getLineBufferImpl()
- Native implementation of getLineBuffer()
parseAndBindImpl
private static boolean parseAndBindImpl(java.lang.String line)
- Native implementation of parseAndBind(String line)
readHistoryFileImpl
private static void readHistoryFileImpl(java.lang.String filename) throws java.io.EOFException, java.io.UnsupportedEncodingException
- Native implementation of readHistoryFile(String filename)
writeHistoryFileImpl
private static void writeHistoryFileImpl(java.lang.String filename) throws java.io.EOFException, java.io.UnsupportedEncodingException
- Native implementation of writeHistoryFile(String filename)
setCompleterImpl
private static void setCompleterImpl(ReadlineCompleter rlc)
- Native implementation of setCompleter(ReadlineCompleter rlc)
getWordBreakCharactersImpl
private static java.lang.String getWordBreakCharactersImpl()
- Native implementation of getWordBreakCharacters()
setWordBreakCharactersImpl
private static void setWordBreakCharactersImpl(java.lang.String wordBreakCharacters) throws java.io.UnsupportedEncodingException
- Native implementation of setWordBreakCharacters()
|
|||||||||
| Home >> All >> org >> gnu >> [ readline overview ] | PREV CLASS NEXT CLASS | ||||||||
SUMMARY: JAVADOC | SOURCE | DOWNLOAD | NESTED | FIELD | CONSTR | METHOD |
DETAIL: FIELD | CONSTR | METHOD | ||||||||
JAVADOC
org.gnu.readline.Readline