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
Modifier and Type | Field and Description |
---|---|
static org.gnu.readline.ReadlineConstInt |
HISTORY_BASE
Constant to access history_base using
getVar() or setVar() . |
static org.gnu.readline.ReadlineConstInt |
HISTORY_LENGTH
Constant to access history_length using
getVar() or setVar() . |
static org.gnu.readline.ReadlineConstInt |
HISTORY_MAX_ENTRIES
Constant to access history_max_entries using
getVar() or setVar() . |
static org.gnu.readline.ReadlineConstString |
HISTORY_NO_EXPAND_CHARS
Constant to access history_no_expand_chars using
getVar() or setVar() . |
static org.gnu.readline.ReadlineConstInt |
HISTORY_QUOTES_EXPANSION
Constant to access history_quotes_inhibit_expansion using
getVar() or setVar() . |
static org.gnu.readline.ReadlineConstString |
HISTORY_SEARCH_DELIMITERS
Constant to access history_search_delimiter_chars using
getVar() or setVar() . |
static org.gnu.readline.ReadlineConstString |
HISTORY_WORD_DELIMITERS
Constant to access history_word_delimiters using
getVar() or setVar() . |
static org.gnu.readline.ReadlineConstInt |
RL_ALREADY_PROMPTED
Constant to access rl_already_prompted using
getVar() or setVar() . |
static org.gnu.readline.ReadlineConstInt |
RL_ATTEMPTED_COMPLETION_OVER
Constant to access rl_attempted_completion_over using
getVar() or setVar() . |
static org.gnu.readline.ReadlineConstString |
RL_BASIC_QUOTE_CHARACTERS
Constant to access rl_basic_quote_characters using
getVar() or setVar() . |
static org.gnu.readline.ReadlineConstString |
RL_BASIC_WORD_BREAK_CHARACTERS
Constant to access rl_basic_word_break_characters using
getVar() or setVar() . |
static org.gnu.readline.ReadlineConstInt |
RL_CATCH_SIGNALS
Constant to access rl_catch_signals using
getVar() or setVar() . |
static org.gnu.readline.ReadlineConstInt |
RL_CATCH_SIGWINCH
Constant to access rl_catch_sigwinch using
getVar() or setVar() . |
static org.gnu.readline.ReadlineConstString |
RL_COMPLETER_QUOTE_CHARACTERS
Constant to access rl_completer_quote_characters using
getVar() or setVar() . |
static org.gnu.readline.ReadlineConstString |
RL_COMPLETER_WORD_BREAK_CHARACTERS
Constant to access rl_completer_word_break_characters using
getVar() or setVar() . |
static org.gnu.readline.ReadlineConstInt |
RL_COMPLETION_APPEND_CHARACTER
Constant to access rl_completion_append_character using
getVar() or setVar() . |
static org.gnu.readline.ReadlineConstInt |
RL_COMPLETION_MARK_SYMLINK_DIRS
Constant to access rl_completion_mark_symlink_dirs using
getVar() or setVar() . |
static org.gnu.readline.ReadlineConstInt |
RL_COMPLETION_QUERY_ITEMS
Constant to access rl_completion_query_items using
getVar() or setVar() . |
static org.gnu.readline.ReadlineConstInt |
RL_COMPLETION_SUPPRESS_APPEND
Constant to access rl_completion_suppress_append using
getVar() or setVar() . |
static org.gnu.readline.ReadlineConstInt |
RL_COMPLETION_TYPE
Constant to access rl_completion_type using
getVar() or setVar() . |
static org.gnu.readline.ReadlineConstInt |
RL_DISPATCHING
Constant to access rl_dispatching using
getVar() or setVar() . |
static org.gnu.readline.ReadlineConstInt |
RL_DONE
Constant to access rl_done using
getVar() or setVar() . |
static org.gnu.readline.ReadlineConstInt |
RL_EDITING_MODE
Constant to access rl_editing_mode using
getVar() or setVar() . |
static org.gnu.readline.ReadlineConstInt |
RL_END
Constant to access rl_end using
getVar() or setVar() . |
static org.gnu.readline.ReadlineConstInt |
RL_ERASE_EMPTY_LINE
Constant to access rl_erase_empty_line using
getVar() or setVar() . |
static org.gnu.readline.ReadlineConstString |
RL_EXECUTING_MACRO
Constant to access rl_executing_macro using
getVar() or setVar() . |
static org.gnu.readline.ReadlineConstInt |
RL_EXPLICIT_ARG
Constant to access rl_explicit_arg using
getVar() or setVar() . |
static org.gnu.readline.ReadlineConstInt |
RL_FILENAME_COMPLETION_DESIRED
Constant to access rl_filename_completion_desired using
getVar() or setVar() . |
static org.gnu.readline.ReadlineConstString |
RL_FILENAME_QUOTE_CHARACTERS
Constant to access rl_filename_quote_characters using
getVar() or setVar() . |
static org.gnu.readline.ReadlineConstInt |
RL_FILENAME_QUOTING_DESIRED
Constant to access rl_filename_quoting_desired using
getVar() or setVar() . |
static org.gnu.readline.ReadlineConstInt |
RL_GNU_READLINE_P
Constant to access rl_gnu_readline_p using
getVar() or setVar() . |
static org.gnu.readline.ReadlineConstInt |
RL_IGNORE_COMPLETION_DUPLICATES
Constant to access rl_ignore_completion_duplicates using
getVar() or setVar() . |
static org.gnu.readline.ReadlineConstInt |
RL_INHIBIT_COMPLETION
Constant to access rl_inhibit_completion using
getVar() or setVar() . |
static org.gnu.readline.ReadlineConstInt |
RL_INSERT_MODE
Constant to access rl_insert_mode using
getVar() or setVar() . |
static org.gnu.readline.ReadlineConstString |
RL_LIBRARY_VERSION
Constant to access rl_library_version using
getVar() or setVar() . |
static org.gnu.readline.ReadlineConstString |
RL_LINE_BUFFER
Constant to access rl_line_buffer using
getVar() or setVar() . |
static org.gnu.readline.ReadlineConstInt |
RL_MARK
Constant to access rl_mark using
getVar() or setVar() . |
static org.gnu.readline.ReadlineConstInt |
RL_NUM_CHARS_TO_READ
Constant to access rl_num_chars_to_read using
getVar() or setVar() . |
static org.gnu.readline.ReadlineConstInt |
RL_NUMERIC_ARG
Constant to access rl_numeric_arg using
getVar() or setVar() . |
static org.gnu.readline.ReadlineConstInt |
RL_PENDING_INPUT
Constant to access rl_pending_input using
getVar() or setVar() . |
static org.gnu.readline.ReadlineConstInt |
RL_POINT
Constant to access rl_point using
getVar() or setVar() . |
static org.gnu.readline.ReadlineConstString |
RL_PROMPT
Constant to access rl_prompt using
getVar() or setVar() . |
static org.gnu.readline.ReadlineConstString |
RL_READLINE_NAME
Constant to access rl_readline_name using
getVar() or setVar() . |
static org.gnu.readline.ReadlineConstInt |
RL_READLINE_STATE
Constant to access rl_readline_state using
getVar() or setVar() . |
static org.gnu.readline.ReadlineConstInt |
RL_READLINE_VERSION
Constant to access rl_readline_version using
getVar() or setVar() . |
static org.gnu.readline.ReadlineConstString |
RL_SPECIAL_PREFIXES
Constant to access rl_special_prefixes using
getVar() or setVar() . |
static org.gnu.readline.ReadlineConstString |
RL_TERMINAL_NAME
Constant to access rl_terminal_name using
getVar() or setVar() . |
Constructor and Description |
---|
Readline() |
Modifier and Type | Method and Description |
---|---|
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 int |
getVar(org.gnu.readline.ReadlineConstInt c)
Query integer readline-variable.
|
static String |
getVar(org.gnu.readline.ReadlineConstString c)
Query string readline-variable.
|
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
|
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 int |
setVar(org.gnu.readline.ReadlineConstInt c,
int value)
Set integer readline-variable.
|
static String |
setVar(org.gnu.readline.ReadlineConstString c,
String value)
Set string readline-variable.
|
static void |
setWordBreakCharacters(String wordBreakCharacters)
Set word break characters.
|
static void |
writeHistoryFile(String filename)
Writes a history file to disc
|
public static final org.gnu.readline.ReadlineConstString RL_LIBRARY_VERSION
getVar()
or setVar()
.
Supporting implementations:
public static final org.gnu.readline.ReadlineConstString RL_READLINE_NAME
getVar()
or setVar()
.
Supporting implementations:
public static final org.gnu.readline.ReadlineConstString RL_PROMPT
getVar()
or setVar()
.
Supporting implementations:
public static final org.gnu.readline.ReadlineConstString RL_LINE_BUFFER
getVar()
or setVar()
.
Supporting implementations:
public static final org.gnu.readline.ReadlineConstString RL_TERMINAL_NAME
getVar()
or setVar()
.
Supporting implementations:
public static final org.gnu.readline.ReadlineConstString RL_EXECUTING_MACRO
getVar()
or setVar()
.
Supporting implementations:
public static final org.gnu.readline.ReadlineConstString RL_BASIC_WORD_BREAK_CHARACTERS
getVar()
or setVar()
.
Supporting implementations:
public static final org.gnu.readline.ReadlineConstString RL_COMPLETER_WORD_BREAK_CHARACTERS
getVar()
or setVar()
.
Supporting implementations:
public static final org.gnu.readline.ReadlineConstString RL_COMPLETER_QUOTE_CHARACTERS
getVar()
or setVar()
.
Supporting implementations:
public static final org.gnu.readline.ReadlineConstString RL_BASIC_QUOTE_CHARACTERS
getVar()
or setVar()
.
Supporting implementations:
public static final org.gnu.readline.ReadlineConstString RL_FILENAME_QUOTE_CHARACTERS
getVar()
or setVar()
.
Supporting implementations:
public static final org.gnu.readline.ReadlineConstString RL_SPECIAL_PREFIXES
getVar()
or setVar()
.
Supporting implementations:
public static final org.gnu.readline.ReadlineConstString HISTORY_WORD_DELIMITERS
getVar()
or setVar()
.
Supporting implementations:
public static final org.gnu.readline.ReadlineConstString HISTORY_NO_EXPAND_CHARS
getVar()
or setVar()
.
Supporting implementations:
public static final org.gnu.readline.ReadlineConstString HISTORY_SEARCH_DELIMITERS
getVar()
or setVar()
.
Supporting implementations:
public static final org.gnu.readline.ReadlineConstInt RL_READLINE_VERSION
getVar()
or setVar()
.
Supporting implementations:
public static final org.gnu.readline.ReadlineConstInt RL_GNU_READLINE_P
getVar()
or setVar()
.
Supporting implementations:
public static final org.gnu.readline.ReadlineConstInt RL_READLINE_STATE
getVar()
or setVar()
.
Supporting implementations:
public static final org.gnu.readline.ReadlineConstInt RL_EDITING_MODE
getVar()
or setVar()
.
Supporting implementations:
public static final org.gnu.readline.ReadlineConstInt RL_INSERT_MODE
getVar()
or setVar()
.
Supporting implementations:
public static final org.gnu.readline.ReadlineConstInt RL_POINT
getVar()
or setVar()
.
Supporting implementations:
public static final org.gnu.readline.ReadlineConstInt RL_END
getVar()
or setVar()
.
Supporting implementations:
public static final org.gnu.readline.ReadlineConstInt RL_MARK
getVar()
or setVar()
.
Supporting implementations:
public static final org.gnu.readline.ReadlineConstInt RL_DONE
getVar()
or setVar()
.
Supporting implementations:
public static final org.gnu.readline.ReadlineConstInt RL_PENDING_INPUT
getVar()
or setVar()
.
Supporting implementations:
public static final org.gnu.readline.ReadlineConstInt RL_DISPATCHING
getVar()
or setVar()
.
Supporting implementations:
public static final org.gnu.readline.ReadlineConstInt RL_EXPLICIT_ARG
getVar()
or setVar()
.
Supporting implementations:
public static final org.gnu.readline.ReadlineConstInt RL_NUMERIC_ARG
getVar()
or setVar()
.
Supporting implementations:
public static final org.gnu.readline.ReadlineConstInt RL_ERASE_EMPTY_LINE
getVar()
or setVar()
.
Supporting implementations:
public static final org.gnu.readline.ReadlineConstInt RL_ALREADY_PROMPTED
getVar()
or setVar()
.
Supporting implementations:
public static final org.gnu.readline.ReadlineConstInt RL_NUM_CHARS_TO_READ
getVar()
or setVar()
.
Supporting implementations:
public static final org.gnu.readline.ReadlineConstInt RL_CATCH_SIGNALS
getVar()
or setVar()
.
Supporting implementations:
public static final org.gnu.readline.ReadlineConstInt RL_CATCH_SIGWINCH
getVar()
or setVar()
.
Supporting implementations:
public static final org.gnu.readline.ReadlineConstInt RL_FILENAME_COMPLETION_DESIRED
getVar()
or setVar()
.
Supporting implementations:
public static final org.gnu.readline.ReadlineConstInt RL_FILENAME_QUOTING_DESIRED
getVar()
or setVar()
.
Supporting implementations:
public static final org.gnu.readline.ReadlineConstInt RL_ATTEMPTED_COMPLETION_OVER
getVar()
or setVar()
.
Supporting implementations:
public static final org.gnu.readline.ReadlineConstInt RL_COMPLETION_TYPE
getVar()
or setVar()
.
Supporting implementations:
public static final org.gnu.readline.ReadlineConstInt RL_COMPLETION_APPEND_CHARACTER
getVar()
or setVar()
.
Supporting implementations:
public static final org.gnu.readline.ReadlineConstInt RL_COMPLETION_SUPPRESS_APPEND
getVar()
or setVar()
.
Supporting implementations:
public static final org.gnu.readline.ReadlineConstInt RL_COMPLETION_QUERY_ITEMS
getVar()
or setVar()
.
Supporting implementations:
public static final org.gnu.readline.ReadlineConstInt RL_COMPLETION_MARK_SYMLINK_DIRS
getVar()
or setVar()
.
Supporting implementations:
public static final org.gnu.readline.ReadlineConstInt RL_IGNORE_COMPLETION_DUPLICATES
getVar()
or setVar()
.
Supporting implementations:
public static final org.gnu.readline.ReadlineConstInt RL_INHIBIT_COMPLETION
getVar()
or setVar()
.
Supporting implementations:
public static final org.gnu.readline.ReadlineConstInt HISTORY_BASE
getVar()
or setVar()
.
Supporting implementations:
public static final org.gnu.readline.ReadlineConstInt HISTORY_LENGTH
getVar()
or setVar()
.
Supporting implementations:
public static final org.gnu.readline.ReadlineConstInt HISTORY_MAX_ENTRIES
getVar()
or setVar()
.
Supporting implementations:
public static final org.gnu.readline.ReadlineConstInt HISTORY_QUOTES_EXPANSION
getVar()
or setVar()
.
Supporting implementations:
public static final void load(ReadlineLibrary lib) throws UnsatisfiedLinkError
lib
- An object (constant) of type ReadlineLibraryUnsatisfiedLinkError
- if the shared library could not be
found. Add it to your LD_LIBRARY_PATH.ReadlineLibrary
public static void initReadline(String applicationName)
Supporting implementations:
applicationName
- Name of application in initialization filepublic static String readline(String prompt) throws EOFException, IOException, UnsupportedEncodingException
Supporting implementations:
prompt
- Prompt to displayEOFException
- on end-of-file, i.e. CTRL-d input.IOException
UnsupportedEncodingException
readline(String,boolean)
,
#addHistory()
public static String readline(String prompt, boolean addToHist) throws EOFException, IOException, 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().)EOFException
- on end-of-file, i.e. CTRL-d input.IOException
UnsupportedEncodingException
readline(String)
,
#addHistory()
public static void addToHistory(String line)
Supporting implementations:
line
- The line to add to the historyUnsupportOperationException
- if underlying library doesn't support
a historypublic static void getHistory(Collection collection)
Supporting implementations:
collection
- where to store the historyUnsupportOperationException
- if underlying library doesn't support
a historypublic static int getHistorySize()
Supporting implementations:
public static void clearHistory()
Supporting implementations:
public static String getHistoryLine(int i)
Supporting implementations:
i
- the index of the entry to returnArrayIndexOutOfBoundsException
- index out of rangepublic static void readInitFile(String filename) throws IOException
Supporting implementations:
filename
- Name of file to read bindings fromIOException
public static boolean parseAndBind(String line)
Supporting implementations:
line
- Simulated line from inputrc filepublic static void readHistoryFile(String filename) throws EOFException, UnsupportedEncodingException
Supporting implementations:
filename
- Name of history file to readEOFException
UnsupportedEncodingException
public static void writeHistoryFile(String filename) throws EOFException, UnsupportedEncodingException
Supporting implementations:
filename
- Name of history file to writeEOFException
UnsupportedEncodingException
public 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 void setWordBreakCharacters(String wordBreakCharacters) throws UnsupportedEncodingException
Supporting implementations:
wordBreakCharacters
- A string of word break charactersUnsupportedEncodingException
public static String getWordBreakCharacters()
Supporting implementations:
public static String getLineBuffer()
ReadlineCompleter
implementation to access the full text
given so far.
Supporting implementations:
public static void setThrowExceptionOnUnsupportedMethod(boolean flag)
flag
- configuration flagpublic static boolean getThrowExceptionOnUnsupportedMethod()
public static void setEncoding(String encoding)
encoding
- encoding to usepublic static String getEncoding()
public static int setVar(org.gnu.readline.ReadlineConstInt c, int value)
c
- symbolic constant of readline-variablevalue
- new value of readline-variablepublic static int getVar(org.gnu.readline.ReadlineConstInt c)
c
- symbolic constant of readline-variablepublic static String setVar(org.gnu.readline.ReadlineConstString c, String value) throws UnsupportedEncodingException
c
- symbolic constant of readline-variablevalue
- new value of readline-variableUnsupportedEncodingException
public static String getVar(org.gnu.readline.ReadlineConstString c) throws UnsupportedEncodingException
c
- symbolic constant of readline-variableUnsupportedEncodingException
Released under the LGPL, (c) Bernhard Bablok, Henner Zeller 1998-2002
Homepage: http://java-readline.sourceforge.net/