|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjline.ConsoleReader
public class 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 | |
---|---|
static String |
CR
|
static SortedMap |
KEYMAP_NAMES
Map that contains the operation name to keymay operation mapping. |
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(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. |
|
ConsoleReader(InputStream in,
Writer out,
InputStream bindings)
|
|
ConsoleReader(InputStream in,
Writer out,
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. |
boolean |
backspace()
Issue a backspace. |
void |
beep()
Issue an audible keyboard bell, if getBellEnabled() return true. |
boolean |
clearScreen()
Clear the screen by issuing the ANSI "clear screen" code. |
static void |
debug(String str)
debug. |
void |
drawLine()
Output put the prompt + the current buffer |
void |
flushConsole()
Flush the console output stream. |
int |
getAutoprintThreshhold()
|
boolean |
getBellEnabled()
|
CompletionHandler |
getCompletionHandler()
|
Collection |
getCompletors()
Returns an unmodifiable list of all the completors. |
CursorBuffer |
getCursorBuffer()
|
String |
getDefaultPrompt()
The default prompt that will be issued. |
Character |
getEchoCharacter()
Returns the echo character. |
History |
getHistory()
|
InputStream |
getInput()
Returns the stream used for console input. |
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. |
boolean |
killLine()
Kill the buffer ahead of the current cursor position. |
boolean |
paste()
Paste the contents of the clipboard into the console buffer |
void |
printColumns(Collection stuff)
Output the specified Collection in proper columns. |
void |
printNewline()
Output a platform-dependant newline. |
void |
printString(String str)
Output the specified string to the output stream (but not the buffer). |
void |
putString(String str)
Write out the specified string to the buffer and the output stream. |
int |
readCharacter(char[] allowed)
|
String |
readLine()
Read the next line and return the contents of the buffer. |
String |
readLine(Character mask)
Read the next line with the specified character mask. |
String |
readLine(String prompt)
|
String |
readLine(String prompt,
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. |
void |
setAutoprintThreshhold(int autoprintThreshhold)
|
void |
setBellEnabled(boolean bellEnabled)
|
void |
setCompletionHandler(CompletionHandler completionHandler)
|
boolean |
setCursorPosition(int position)
Move the cursor position to the specified absolute index. |
void |
setDebug(PrintWriter debugger)
Set the stream for debugging. |
void |
setDefaultPrompt(String prompt)
The default prompt that will be issued. |
void |
setEchoCharacter(Character echoCharacter)
Set the echo character. |
void |
setHistory(History history)
|
void |
setInput(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 |
---|
public static final String CR
public static SortedMap KEYMAP_NAMES
Constructor Detail |
---|
public ConsoleReader() throws IOException
FileDescriptor.in
for input
and System.out
for output. FileDescriptor.in
is
used because it has a better chance of being unbuffered.
IOException
public ConsoleReader(InputStream in, Writer out) throws IOException
InputStream
for input and the specific writer for output, using the
default keybindings resource.
IOException
public ConsoleReader(InputStream in, Writer out, InputStream bindings) throws IOException
IOException
public ConsoleReader(InputStream in, Writer out, InputStream bindings, Terminal term) throws IOException
in
- the inputout
- the outputbindings
- the key bindings to useterm
- the terminal to use
IOException
Method Detail |
---|
public Terminal getTerminal()
public void setDebug(PrintWriter debugger)
public void setInput(InputStream in)
public InputStream getInput()
public String readLine() throws IOException
IOException
public String readLine(Character mask) throws IOException
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()
public String readLine(String prompt) throws IOException
IOException
public void setDefaultPrompt(String prompt)
public String getDefaultPrompt()
public String readLine(String prompt, Character mask) throws IOException
InputStream
, and
return the line (without any trailing newlines).
prompt
- the prompt to issue to the console, may be null.
IOException
public boolean paste() throws IOException
IOException
public boolean killLine() throws IOException
IOException
public boolean clearScreen() throws IOException
IOException
public CursorBuffer getCursorBuffer()
public void printColumns(Collection stuff) throws IOException
Collection
in proper columns.
stuff
- the stuff to print
IOException
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 Collection getCompletors()
public final boolean setCursorPosition(int position) throws IOException
IOException
public final void redrawLine() throws IOException
IOException
public final void drawLine() throws IOException
IOException
public final void printNewline() throws IOException
IOException
public final void putString(String str) throws IOException
IOException
public final void printString(String str) throws IOException
IOException
public final void beep() throws IOException
getBellEnabled()
return true.
IOException
public final void flushConsole() throws IOException
IOException
public final boolean backspace() throws IOException
IOException
public static void debug(String str)
str
- the message to issue.public final int readVirtualKey() throws IOException
IOException
public final int readCharacter(char[] allowed) throws IOException
IOException
public void setHistory(History history)
public History getHistory()
public void setCompletionHandler(CompletionHandler completionHandler)
public CompletionHandler getCompletionHandler()
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
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 Character getEchoCharacter()
public void setUseHistory(boolean useHistory)
public boolean getUseHistory()
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |