|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjline.ConsoleReader
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.
Field Summary | |
private int |
autoprintThreshhold
The number of tab-completion candidates above which a warning will be prompted before showing all the candidates. |
private boolean |
bellEnabled
If true, issue an audible keyboard bell when appropriate. |
(package private) CursorBuffer |
buf
|
private CompletionHandler |
completionHandler
|
(package private) java.util.List |
completors
|
static java.lang.String |
CR
|
(package private) static java.io.PrintWriter |
debugger
|
private java.lang.Character |
echoCharacter
|
(package private) History |
history
|
(package private) java.io.InputStream |
in
|
private short[] |
keybindings
The map for logical operations. |
static java.util.SortedMap |
KEYMAP_NAMES
Map that contains the operation name to keymay operation mapping. |
private java.lang.Character |
mask
The current character mask. |
private static java.lang.Character |
NULL_MASK
The null mask. |
(package private) java.io.Writer |
out
|
(package private) java.lang.String |
prompt
|
private Terminal |
terminal
The Terminal to use. |
private boolean |
useHistory
|
Fields inherited from interface jline.ConsoleOperations |
ADD, BACKSPACE, CHANGE_CASE, CHANGE_META, CLEAR_SCREEN, COMPLETE, CTRL_A, CTRL_B, CTRL_C, CTRL_D, CTRL_E, CTRL_F, CTRL_N, CTRL_P, DELETE_META, DELETE_NEXT_CHAR, DELETE_PREV_CHAR, DELETE_PREV_WORD, END_WORD, EXIT, INSERT, KEYBOARD_BELL, KILL_LINE, KILL_LINE_PREV, MOVE_TO_BEG, MOVE_TO_END, NEWLINE, NEXT_CHAR, NEXT_HISTORY, NEXT_SPACE_WORD, NEXT_WORD, PASTE, PASTE_NEXT, PASTE_PREV, PREV_CHAR, PREV_HISTORY, PREV_SPACE_WORD, PREV_WORD, REDISPLAY, REPEAT_NEXT_CHAR, REPEAT_PREV_CHAR, REPEAT_SEARCH_NEXT, REPEAT_SEARCH_PREV, REPLACE_CHAR, REPLACE_MODE, RESET_LINE, SEARCH_NEXT, SEARCH_PREV, SUBSTITUTE_CHAR, SUBSTITUTE_LINE, TO_END_WORD, TO_NEXT_CHAR, TO_PREV_CHAR, UNDO, UNKNOWN |
Constructor Summary | |
ConsoleReader()
Create a new reader using FileDescriptor.in for input
and System.out for output. |
|
ConsoleReader(java.io.InputStream in,
java.io.Writer out)
Create a new reader using the specified InputStream
for input and the specific writer for output, using the
default keybindings resource. |
|
ConsoleReader(java.io.InputStream in,
java.io.Writer out,
java.io.InputStream bindings)
|
|
ConsoleReader(java.io.InputStream in,
java.io.Writer out,
java.io.InputStream bindings,
Terminal term)
Create a new reader. |
Method Summary | |
boolean |
addCompletor(Completor completor)
Add the specified Completor to the list of handlers
for tab-completion. |
private void |
back(int num)
Move the visual cursor backwards without modifying the buffer cursor. |
boolean |
backspace()
Issue a backspace. |
private int |
backspace(int num)
Issue num backspaces. |
private int |
backspaceAll()
|
void |
beep()
Issue an audible keyboard bell, if getBellEnabled() return true. |
private void |
clearAhead(int num)
Clear ahead the specified number of characters without moving the cursor. |
(package private) int |
clearEcho(int c)
Clear the echoed characters for the specified character code. |
boolean |
clearScreen()
Clear the screen by issuing the ANSI "clear screen" code. |
private boolean |
complete()
Use the completors to modify the buffer with the appropriate completions. |
private void |
consumeException(java.lang.Throwable e)
No-op for exceptions we want to silently consume. |
(package private) int |
countEchoCharacters(char c)
|
static void |
debug(java.lang.String str)
debug. |
private boolean |
deleteCurrentCharacter()
Delete the character at the current position and redraw the remainder of the buffer. |
private boolean |
deletePreviousWord()
|
private void |
drawBuffer()
Redraw the rest of the buffer from the cursor onwards. |
private void |
drawBuffer(int clear)
Redraw the rest of the buffer from the cursor onwards. |
void |
drawLine()
Output put the prompt + the current buffer |
(package private) java.lang.String |
finishBuffer()
Clear the buffer and add its contents to the history. |
void |
flushConsole()
Flush the console output stream. |
int |
getAutoprintThreshhold()
|
boolean |
getBellEnabled()
|
CompletionHandler |
getCompletionHandler()
|
java.util.Collection |
getCompletors()
Returns an unmodifiable list of all the completors. |
CursorBuffer |
getCursorBuffer()
|
(package private) int |
getCursorPosition()
|
java.lang.String |
getDefaultPrompt()
The default prompt that will be issued. |
java.lang.Character |
getEchoCharacter()
Returns the echo character. |
History |
getHistory()
|
java.io.InputStream |
getInput()
Returns the stream used for console input. |
(package private) int |
getKeyForAction(short logicalAction)
|
(package private) java.lang.StringBuffer |
getPrintableCharacters(char ch)
Return the number of characters that will be printed when the specified character is echoed to the screen. |
int |
getTermheight()
Query the terminal to find the current width; |
Terminal |
getTerminal()
|
int |
getTermwidth()
Query the terminal to find the current width; |
boolean |
getUseHistory()
Whether or not to add new commands to the history buffer. |
private boolean |
isDelimiter(char c)
Checks to see if the specified character is a delimiter. |
boolean |
killLine()
Kill the buffer ahead of the current cursor position. |
private int |
moveCursor(int num)
Move the cursor where characters. |
private boolean |
moveHistory(boolean next)
Move up or down the history tree. |
private void |
moveInternal(int where)
Move the cursor where characters, withough checking the current buffer. |
private boolean |
moveToEnd()
|
private boolean |
nextWord()
|
private void |
pad(java.lang.String toPad,
int len,
java.lang.StringBuffer appendTo)
Append toPad to the specified appendTo, as well as (toPad.length () - len) spaces. |
boolean |
paste()
Paste the contents of the clipboard into the console buffer |
private boolean |
previousWord()
|
private void |
printCharacter(int c)
Output the specified character to the output stream without manipulating the current buffer. |
private void |
printCharacters(char[] c)
Output the specified characters to the output stream without manipulating the current buffer. |
private void |
printCharacters(char c,
int num)
|
void |
printColumns(java.util.Collection stuff)
Output the specified Collection in proper columns. |
void |
printNewline()
Output a platform-dependant newline. |
void |
printString(java.lang.String str)
Output the specified string to the output stream (but not the buffer). |
private void |
putChar(int c,
boolean print)
Output the specified character, both to the buffer and the output stream. |
void |
putString(java.lang.String str)
Write out the specified string to the buffer and the output stream. |
private int[] |
readBinding()
Reads the console input and returns an array of the form [raw, key binding]. |
int |
readCharacter(char[] allowed)
|
java.lang.String |
readLine()
Read the next line and return the contents of the buffer. |
java.lang.String |
readLine(java.lang.Character mask)
Read the next line with the specified character mask. |
private java.lang.String |
readLine(java.io.InputStream in)
|
java.lang.String |
readLine(java.lang.String prompt)
|
java.lang.String |
readLine(java.lang.String prompt,
java.lang.Character mask)
Read a line from the in InputStream , and
return the line (without any trailing newlines). |
int |
readVirtualKey()
Read a character from the console. |
void |
redrawLine()
Clear the line and redraw it. |
boolean |
removeCompletor(Completor completor)
Remove the specified Completor from the list of handlers
for tab-completion. |
(package private) boolean |
resetLine()
Erase the current line. |
void |
setAutoprintThreshhold(int autoprintThreshhold)
|
void |
setBellEnabled(boolean bellEnabled)
|
private void |
setBuffer(java.lang.String buffer)
Set the current buffer's content to the specified String . |
void |
setCompletionHandler(CompletionHandler completionHandler)
|
boolean |
setCursorPosition(int position)
Move the cursor position to the specified absolute index. |
void |
setDebug(java.io.PrintWriter debugger)
Set the stream for debugging. |
void |
setDefaultPrompt(java.lang.String prompt)
The default prompt that will be issued. |
void |
setEchoCharacter(java.lang.Character echoCharacter)
Set the echo character. |
void |
setHistory(History history)
|
void |
setInput(java.io.InputStream in)
Set the stream to be used for console input. |
void |
setUseHistory(boolean useHistory)
Whether or not to add new commands to the history buffer. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
java.lang.String prompt
private boolean useHistory
public static final java.lang.String CR
public static java.util.SortedMap KEYMAP_NAMES
private final short[] keybindings
private boolean bellEnabled
private java.lang.Character mask
private static final java.lang.Character NULL_MASK
private int autoprintThreshhold
private final Terminal terminal
private CompletionHandler completionHandler
java.io.InputStream in
final java.io.Writer out
final CursorBuffer buf
static java.io.PrintWriter debugger
History history
final java.util.List completors
private java.lang.Character echoCharacter
Constructor Detail |
public ConsoleReader() throws java.io.IOException
FileDescriptor.in
for input
and System.out
for output. FileDescriptor.in
is
used because it has a better chance of being unbuffered.
public ConsoleReader(java.io.InputStream in, java.io.Writer out) throws java.io.IOException
InputStream
for input and the specific writer for output, using the
default keybindings resource.
public ConsoleReader(java.io.InputStream in, java.io.Writer out, java.io.InputStream bindings) throws java.io.IOException
public ConsoleReader(java.io.InputStream in, java.io.Writer out, java.io.InputStream bindings, Terminal term) throws java.io.IOException
in
- the inputout
- the outputbindings
- the key bindings to useterm
- the terminal to useMethod Detail |
public Terminal getTerminal()
public void setDebug(java.io.PrintWriter debugger)
public void setInput(java.io.InputStream in)
public java.io.InputStream getInput()
public java.lang.String readLine() throws java.io.IOException
java.io.IOException
public java.lang.String readLine(java.lang.Character mask) throws java.io.IOException
java.io.IOException
public void setBellEnabled(boolean bellEnabled)
bellEnabled
- if true, enable audible keyboard bells if
an alert is required.public boolean getBellEnabled()
public int getTermwidth()
Terminal.getTerminalWidth()
public int getTermheight()
Terminal.getTerminalHeight()
public void setAutoprintThreshhold(int autoprintThreshhold)
autoprintThreshhold
- the number of candidates to print
without issuing a warning.public int getAutoprintThreshhold()
int getKeyForAction(short logicalAction)
int clearEcho(int c) throws java.io.IOException
java.io.IOException
int countEchoCharacters(char c)
java.lang.StringBuffer getPrintableCharacters(char ch)
int getCursorPosition()
public java.lang.String readLine(java.lang.String prompt) throws java.io.IOException
java.io.IOException
public void setDefaultPrompt(java.lang.String prompt)
public java.lang.String getDefaultPrompt()
public java.lang.String readLine(java.lang.String prompt, java.lang.Character mask) throws java.io.IOException
InputStream
, and
return the line (without any trailing newlines).
prompt
- the prompt to issue to the console, may be null.
java.io.IOException
private java.lang.String readLine(java.io.InputStream in) throws java.io.IOException
java.io.IOException
private int[] readBinding() throws java.io.IOException
java.io.IOException
private final boolean moveHistory(boolean next) throws java.io.IOException
java.io.IOException
public boolean paste() throws java.io.IOException
java.io.IOException
public boolean killLine() throws java.io.IOException
java.io.IOException
public boolean clearScreen() throws java.io.IOException
java.io.IOException
private final boolean complete() throws java.io.IOException
java.io.IOException
public CursorBuffer getCursorBuffer()
public void printColumns(java.util.Collection stuff) throws java.io.IOException
Collection
in proper columns.
stuff
- the stuff to print
java.io.IOException
private final void pad(java.lang.String toPad, int len, java.lang.StringBuffer appendTo)
toPad
- the String
to padlen
- the target lengthappendTo
- the StringBuffer
to which to append the
padded String
.public boolean addCompletor(Completor completor)
Completor
to the list of handlers
for tab-completion.
completor
- the Completor
to add
public boolean removeCompletor(Completor completor)
Completor
from the list of handlers
for tab-completion.
completor
- the Completor
to remove
public java.util.Collection getCompletors()
final boolean resetLine() throws java.io.IOException
java.io.IOException
public final boolean setCursorPosition(int position) throws java.io.IOException
java.io.IOException
private final void setBuffer(java.lang.String buffer) throws java.io.IOException
String
. The visual console will be modified
to show the current buffer.
buffer
- the new contents of the buffer.
java.io.IOException
public final void redrawLine() throws java.io.IOException
java.io.IOException
public final void drawLine() throws java.io.IOException
java.io.IOException
public final void printNewline() throws java.io.IOException
java.io.IOException
final java.lang.String finishBuffer()
public final void putString(java.lang.String str) throws java.io.IOException
java.io.IOException
public final void printString(java.lang.String str) throws java.io.IOException
java.io.IOException
private final void putChar(int c, boolean print) throws java.io.IOException
java.io.IOException
private final void drawBuffer(int clear) throws java.io.IOException
clear
- the number of characters to clear after the
end of the buffer
java.io.IOException
private final void drawBuffer() throws java.io.IOException
java.io.IOException
private final void clearAhead(int num) throws java.io.IOException
java.io.IOException
private final void back(int num) throws java.io.IOException
java.io.IOException
public final void beep() throws java.io.IOException
getBellEnabled()
return true.
java.io.IOException
private final void printCharacter(int c) throws java.io.IOException
java.io.IOException
private final void printCharacters(char[] c) throws java.io.IOException
java.io.IOException
private final void printCharacters(char c, int num) throws java.io.IOException
java.io.IOException
public final void flushConsole() throws java.io.IOException
java.io.IOException
private final int backspaceAll() throws java.io.IOException
java.io.IOException
private final int backspace(int num) throws java.io.IOException
java.io.IOException
public final boolean backspace() throws java.io.IOException
java.io.IOException
private final boolean moveToEnd() throws java.io.IOException
java.io.IOException
private final boolean deleteCurrentCharacter() throws java.io.IOException
java.io.IOException
private final boolean previousWord() throws java.io.IOException
java.io.IOException
private final boolean nextWord() throws java.io.IOException
java.io.IOException
private final boolean deletePreviousWord() throws java.io.IOException
java.io.IOException
private final int moveCursor(int num) throws java.io.IOException
java.io.IOException
public static void debug(java.lang.String str)
str
- the message to issue.private final void moveInternal(int where) throws java.io.IOException
where
- the number of characters to move to the right or left.
java.io.IOException
#where
public final int readVirtualKey() throws java.io.IOException
java.io.IOException
public final int readCharacter(char[] allowed) throws java.io.IOException
java.io.IOException
public void setHistory(History history)
public History getHistory()
public void setCompletionHandler(CompletionHandler completionHandler)
public CompletionHandler getCompletionHandler()
public void setEchoCharacter(java.lang.Character echoCharacter)
Set the echo character. For example, to have "*" entered when a password is typed:
myConsoleReader.setEchoCharacter (new Character ('*'));
Setting the character to
nullwill 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.public java.lang.Character getEchoCharacter()
private void consumeException(java.lang.Throwable e)
private boolean isDelimiter(char c)
c
- the character to test
public void setUseHistory(boolean useHistory)
public boolean getUseHistory()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |