public class ConsoleReader extends java.lang.Object implements ConsoleOperations
Terminal.initializeTerminal()
for convenience
methods for issuing platform-specific setup commands.Modifier and Type | Field and Description |
---|---|
static java.lang.String |
CR |
static java.util.SortedMap |
KEYMAP_NAMES
Map that contains the operation name to keymay operation mapping.
|
ADD, BACKSPACE, CHANGE_CASE, CHANGE_META, CLEAR_LINE, CLEAR_SCREEN, COMPLETE, CTRL_A, CTRL_B, CTRL_C, CTRL_D, CTRL_E, CTRL_F, CTRL_K, CTRL_L, CTRL_N, CTRL_OB, CTRL_P, CTRL_QM, DELETE, DELETE_META, DELETE_NEXT_CHAR, DELETE_PREV_CHAR, DELETE_PREV_WORD, END_OF_HISTORY, 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, QUESTION_MARK, REDISPLAY, REPEAT_NEXT_CHAR, REPEAT_PREV_CHAR, REPEAT_SEARCH_NEXT, REPEAT_SEARCH_PREV, REPLACE_CHAR, REPLACE_MODE, RESET_LINE, SEARCH_NEXT, SEARCH_PREV, START_OF_HISTORY, SUBSTITUTE_CHAR, SUBSTITUTE_LINE, TO_END_WORD, TO_NEXT_CHAR, TO_PREV_CHAR, UNDO, UNKNOWN
Constructor and Description |
---|
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.
|
Modifier and Type | Method and Description |
---|---|
boolean |
addCompletor(Completor completor)
Add the specified
Completor to the list of handlers for
tab-completion. |
void |
addTriggeredAction(char c,
java.awt.event.ActionListener listener)
Adding a triggered Action allows to give another curse of action
if a character passed the preprocessing.
|
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(java.lang.String str)
debug.
|
boolean |
delete()
Issue a remove.
|
void |
drawLine()
Output put the prompt + the current buffer
|
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() |
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.
|
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 |
getUsePagination()
Whether to use pagination when the number of rows of candidates exceeds
the height of the temrinal.
|
boolean |
killLine()
Kill the buffer ahead of the current cursor position.
|
int |
moveCursor(int num)
Move the cursor where characters.
|
boolean |
paste()
Paste the contents of the clipboard into the console buffer
|
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).
|
void |
putString(java.lang.String str)
Write out the specified string to the buffer and the output stream.
|
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.
|
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. |
boolean |
replace(int num,
java.lang.String replacement) |
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(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.
|
void |
setUsePagination(boolean usePagination)
Whether to use pagination when the number of rows of candidates exceeds
the height of the temrinal.
|
public static final java.lang.String CR
public static java.util.SortedMap KEYMAP_NAMES
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.java.io.IOException
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.java.io.IOException
public ConsoleReader(java.io.InputStream in, java.io.Writer out, java.io.InputStream bindings) throws java.io.IOException
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 usejava.io.IOException
public void addTriggeredAction(char c, java.awt.event.ActionListener listener)
Say you want to disconnect the application if the user enter q. addTriggerAction('q', new ActionListener(){ System.exit(0); }); would do the trick.
c
- listener
- 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()
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
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
public CursorBuffer getCursorBuffer()
public void printColumns(java.util.Collection stuff) throws java.io.IOException
Collection
in proper columns.stuff
- the stuff to printjava.io.IOException
public boolean addCompletor(Completor completor)
Completor
to the list of handlers for
tab-completion.completor
- the Completor
to addpublic boolean removeCompletor(Completor completor)
Completor
from the list of handlers for
tab-completion.completor
- the Completor
to removeNativepublic java.util.Collection getCompletors()
public final boolean setCursorPosition(int position) throws java.io.IOException
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
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
public final void beep() throws java.io.IOException
getBellEnabled()
return true.java.io.IOException
public final void flushConsole() throws java.io.IOException
java.io.IOException
public final boolean backspace() throws java.io.IOException
java.io.IOException
public final int moveCursor(int num) throws java.io.IOException
where
- if less than 0, move abs(where) to the left,
otherwise move where to the right.java.io.IOException
public static void debug(java.lang.String str)
str
- the message to issue.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 final boolean replace(int num, java.lang.String replacement)
public final boolean delete() 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
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.public java.lang.Character getEchoCharacter()
public void setUseHistory(boolean useHistory)
public boolean getUseHistory()
public void setUsePagination(boolean usePagination)
public boolean getUsePagination()
Copyright (c) 2014 Cloud Software Group, Inc. All rights reserved.