CR
public static final String CR
KEYMAP_NAMES
public static SortedMap KEYMAP_NAMES
Map that contains the operation name to keymay operation mapping.
NULL_MASK
private static final Character NULL_MASK
The null mask.
TAB_WIDTH
(package private) static final int TAB_WIDTH
autoprintThreshhold
private int autoprintThreshhold
The number of tab-completion candidates above which a warning will be
prompted before showing all the candidates.
bellEnabled
private boolean bellEnabled
If true, issue an audible keyboard bell when appropriate.
completors
(package private) final List completors
debugger
(package private) static PrintWriter debugger
echoCharacter
private Character echoCharacter
history
(package private) History history
in
(package private) InputStream in
keybindings
private final short[] keybindings
The map for logical operations.
loc
private static ResourceBundle loc
mask
private Character mask
The current character mask.
out
(package private) final Writer out
prompt
(package private) String prompt
terminal
private final Terminal terminal
The Terminal to use.
triggeredActions
private Map triggeredActions
useHistory
private boolean useHistory
usePagination
private boolean usePagination
addCompletor
public boolean addCompletor(Completor completor)
Add the specified
Completor
to the list of handlers for
tab-completion.
- true if it was successfully added
addTriggeredAction
public void addTriggeredAction(char c,
ActionListener listener)
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.
back
private final void back(int num)
throws IOException
Move the visual cursor backwards without modifying the buffer cursor.
backspace
public final boolean backspace()
throws IOException
Issue a backspace.
backspace
private final int backspace(int num)
throws IOException
Issue num backspaces.
- the number of characters backed up
backspaceAll
private final int backspaceAll()
throws IOException
beep
public final void beep()
throws IOException
clearAhead
private final void clearAhead(int num)
throws IOException
Clear ahead the specified number of characters without moving the cursor.
clearEcho
(package private) int clearEcho(int c)
throws IOException
Clear the echoed characters for the specified character code.
clearScreen
public boolean clearScreen()
throws IOException
Clear the screen by issuing the ANSI "clear screen" code.
complete
private final boolean complete()
throws IOException
Use the completors to modify the buffer with the appropriate completions.
consumeException
private void consumeException(Throwable e)
No-op for exceptions we want to silently consume.
countEchoCharacters
(package private) int countEchoCharacters(char c)
debug
public static void debug(String str)
debug.
str
- the message to issue.
delete
public final boolean delete()
throws IOException
Issue a delete.
delete
private final int delete(int num)
throws IOException
Issue num deletes.
- the number of characters backed up
deleteCurrentCharacter
private final boolean deleteCurrentCharacter()
throws IOException
Delete the character at the current position and redraw the remainder of
the buffer.
deletePreviousWord
private final boolean deletePreviousWord()
throws IOException
drawBuffer
private final void drawBuffer()
throws IOException
Redraw the rest of the buffer from the cursor onwards. This is necessary
for inserting text into the buffer.
drawBuffer
private final void drawBuffer(int clear)
throws IOException
Redraw the rest of the buffer from the cursor onwards. This is necessary
for inserting text into the buffer.
clear
- the number of characters to clear after the end of the buffer
drawLine
public final void drawLine()
throws IOException
Output put the prompt + the current buffer
finishBuffer
(package private) final String finishBuffer()
Clear the buffer and add its contents to the history.
- the former contents of the buffer.
flushConsole
public final void flushConsole()
throws IOException
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.
getAutoprintThreshhold
public int getAutoprintThreshhold()
- the number of candidates to print without issing a warning.
getBellEnabled
public boolean getBellEnabled()
- true is audible keyboard bell is enabled.
getCompletors
public Collection getCompletors()
Returns an unmodifiable list of all the completors.
getCursorPosition
(package private) int getCursorPosition()
getDefaultPrompt
public String getDefaultPrompt()
The default prompt that will be issued.
getEchoCharacter
public Character getEchoCharacter()
Returns the echo character.
getHistory
public History getHistory()
getInput
public InputStream getInput()
Returns the stream used for console input.
getKeyForAction
(package private) int getKeyForAction(short logicalAction)
getPrintableCharacters
(package private) StringBuffer getPrintableCharacters(char ch)
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.
getTermheight
public int getTermheight()
Query the terminal to find the current width;
- the height of the current terminal.
getTerminal
public Terminal getTerminal()
getTermwidth
public int getTermwidth()
Query the terminal to find the current width;
- the width of the current terminal.
getUseHistory
public boolean getUseHistory()
Whether or not to add new commands to the history buffer.
getUsePagination
public boolean getUsePagination()
Whether to use pagination when the number of rows of candidates exceeds
the height of the temrinal.
isDelimiter
private boolean isDelimiter(char c)
Checks to see if the specified character is a delimiter. We consider a
character a delimiter if it is anything but a letter or digit.
c
- the character to test
- true if it is a delimiter
killLine
public boolean killLine()
throws IOException
Kill the buffer ahead of the current cursor position.
moveCursor
public final int moveCursor(int num)
throws IOException
Move the cursor where characters.
- the number of spaces we moved
moveHistory
private final boolean moveHistory(boolean next)
throws IOException
Move up or down the history tree.
moveInternal
private final void moveInternal(int where)
throws IOException
Move the cursor where characters, withough checking the current
buffer.
where
- the number of characters to move to the right or left.
moveToEnd
private final boolean moveToEnd()
throws IOException
nextWord
private final boolean nextWord()
throws IOException
pad
private final void pad(String toPad,
int len,
StringBuffer appendTo)
Append toPad to the specified appendTo, as well as (toPad.length () -
len) spaces.
toPad
- the String
to padlen
- the target lengthappendTo
- the StringBuffer
to which to append the padded
String
.
paste
public boolean paste()
throws IOException
Paste the contents of the clipboard into the console buffer
- true if clipboard contents pasted
previousWord
private final boolean previousWord()
throws IOException
printCharacter
private final void printCharacter(int c)
throws IOException
Output the specified character to the output stream without manipulating
the current buffer.
printCharacters
private final void printCharacters(char c,
int num)
throws IOException
printCharacters
private final void printCharacters(char[] c)
throws IOException
Output the specified characters to the output stream without manipulating
the current buffer.
printColumns
public void printColumns(Collection stuff)
throws IOException
Output the specified Collection
in proper columns.
stuff
- the stuff to print
printNewline
public final void printNewline()
throws IOException
Output a platform-dependant newline.
printString
public final void printString(String str)
throws IOException
Output the specified string to the output stream (but not the buffer).
putChar
private final void putChar(int c,
boolean print)
throws IOException
Output the specified character, both to the buffer and the output stream.
putString
public final void putString(String str)
throws IOException
Write out the specified string to the buffer and the output stream.
readBinding
private int[] readBinding()
throws IOException
Reads the console input and returns an array of the form [raw, key
binding].
readCharacter
public final int readCharacter(char[] allowed)
throws IOException
readLine
public String readLine()
throws IOException
Read the next line and return the contents of the buffer.
readLine
public String readLine(Character mask)
throws IOException
Read the next line with the specified character mask. If null, then
characters will be echoed. If 0, then no characters will be echoed.
readLine
private String readLine(InputStream in)
throws IOException
readLine
public String readLine(String prompt)
throws IOException
readLine
public String readLine(String prompt,
Character mask)
throws IOException
Read a line from the in InputStream
, and return the line
(without any trailing newlines).
prompt
- the prompt to issue to the console, may be null.
- a line that is read from the terminal, or null if there was null
input (e.g., CTRL-D was pressed).
readVirtualKey
public final int readVirtualKey()
throws IOException
Read a character from the console.
- the character, or -1 if an EOF is received.
redrawLine
public final void redrawLine()
throws IOException
Clear the line and redraw it.
removeCompletor
public boolean removeCompletor(Completor completor)
Remove the specified
Completor
from the list of handlers for
tab-completion.
- true if it was successfully removed
replace
public final boolean replace(int num,
String replacement)
resetLine
(package private) final boolean resetLine()
throws IOException
Erase the current line.
- false if we failed (e.g., the buffer was empty)
setAutoprintThreshhold
public void setAutoprintThreshhold(int autoprintThreshhold)
autoprintThreshhold
- the number of candidates to print without issuing a warning.
setBellEnabled
public void setBellEnabled(boolean bellEnabled)
bellEnabled
- if true, enable audible keyboard bells if an alert is
required.
setBuffer
private final void setBuffer(String buffer)
throws IOException
Set the current buffer's content to the specified String
. The
visual console will be modified to show the current buffer.
buffer
- the new contents of the buffer.
setCompletionHandler
public void setCompletionHandler(CompletionHandler completionHandler)
setCursorPosition
public final boolean setCursorPosition(int position)
throws IOException
Move the cursor position to the specified absolute index.
setDebug
public void setDebug(PrintWriter debugger)
Set the stream for debugging. Development use only.
setDefaultPrompt
public void setDefaultPrompt(String prompt)
The default prompt that will be issued.
setEchoCharacter
public void setEchoCharacter(Character echoCharacter)
Set the echo character. For example, to have "*" entered when a password
is typed:
myConsoleReader.setEchoCharacter(new Character('*'));
Setting the character to
null
will restore normal character echoing. Setting the character to
new Character(0)
will cause nothing to be echoed.
echoCharacter
- the character to echo to the console in place of the typed
character.
setHistory
public void setHistory(History history)
setInput
public void setInput(InputStream in)
Set the stream to be used for console input.
setUseHistory
public void setUseHistory(boolean useHistory)
Whether or not to add new commands to the history buffer.
setUsePagination
public void setUsePagination(boolean usePagination)
Whether to use pagination when the number of rows of candidates exceeds
the height of the temrinal.