A reader for console applications. It supports custom tab-completion,
saveable command history, and command line editing. On some platforms,
platform-specific commands will need to be issued before the reader will
function properly. See
Terminal.initializeTerminal for convenience
methods for issuing platform-specific setup commands.
author: Marc Prud'hommeaux
ConsoleReader() Create a new reader using
FileDescriptor.in for input and
System.out for output.
public
ConsoleReader(InputStream in, Writer out) Create a new reader using the specified
InputStream for input and
the specific writer for output, using the default keybindings resource.
addTriggeredAction(char c, ActionListener listener) Adding a triggered Action allows to give another curse of action
if a character passed the preprocessing.
getUseHistory() Whether or not to add new commands to the history buffer.
public boolean
getUsePagination() Whether to use pagination when the number of rows of candidates exceeds
the height of the temrinal.
public boolean
killLine() Kill the buffer ahead of the current cursor position.
final public int
moveCursor(int num) Move the cursor where characters.
Parameters: where - if less than 0, move abs(where) to the left,otherwise move where to the right.
readLine(String prompt, Character mask) Read a line from the inInputStream , and return the line
(without any trailing newlines).
Parameters: prompt - the prompt to issue to the console, may be null.
Create a new reader using
FileDescriptor.in for input and
System.out for output.
FileDescriptor.in is used because
it has a better chance of being unbuffered.
Create a new reader.
Parameters: in - the input Parameters: out - the output Parameters: bindings - the key bindings to use Parameters: term - the terminal to use
Adding a triggered Action allows to give another curse of action
if a character passed the preprocessing.
Say you want to close the application if the user enter q.
addTriggerAction('q', new ActionListener(){ System.exit(0); });
would do the trick.
Parameters: c - Parameters: listener -
Flush the console output stream. This is important for printout out
single characters (like a backspace or keyboard) that we want the console
to handle immedately.
Return the number of characters that will be printed when the specified
character is echoed to the screen. Adapted from cat by Torbjorn Granlund,
as repeated in stty by David MacKenzie.
Move the cursor where characters.
Parameters: where - if less than 0, move abs(where) to the left,otherwise move where to the right. the number of spaces we moved
Read a line from the inInputStream , and return the line
(without any trailing newlines).
Parameters: prompt - the prompt to issue to the console, may be null. a line that is read from the terminal, or null if there was nullinput (e.g., CTRL-D was pressed).
Remove the specified
Completor from the list of handlers for
tab-completion.
Parameters: completor - the Completor to remove true if it was successfully removed
replace
final public boolean replace(int num, String replacement)(Code)