public class ConsoleReader extends Object
Terminal.init()
for convenience
methods for issuing platform-specific setup commands.Modifier and Type | Field and Description |
---|---|
static char |
BACKSPACE |
static String |
CR |
static String |
DEFAULT_INPUT_RC |
static String |
INPUT_RC |
static String |
JLINE_COMPLETION_THRESHOLD |
static String |
JLINE_ESC_TIMEOUT |
static String |
JLINE_INPUTRC |
static String |
JLINE_NOBELL |
static char |
KEYBOARD_BELL |
static char |
NULL_MASK |
static char |
RESET_LINE |
static int |
TAB_WIDTH |
Constructor and Description |
---|
ConsoleReader() |
ConsoleReader(InputStream in,
OutputStream out) |
ConsoleReader(InputStream in,
OutputStream out,
Terminal term) |
ConsoleReader(String appName,
InputStream in,
OutputStream out,
Terminal term) |
ConsoleReader(String appName,
InputStream in,
OutputStream out,
Terminal term,
String encoding) |
Modifier and Type | Method and Description |
---|---|
String |
accept()
The equivalent of hitting <RET>.
|
boolean |
addCompleter(Completer completer)
Add the specified
Completer to the list of handlers for tab-completion. |
void |
addTriggeredAction(char c,
ActionListener listener)
Adding a triggered Action allows to give another curse of action if a character passed the pre-processing.
|
protected void |
back(int num)
Move the visual cursor backwards without modifying the buffer cursor.
|
boolean |
backspace()
Issue a backspace.
|
void |
beep()
Issue an audible keyboard bell.
|
boolean |
clearScreen()
Clear the screen by issuing the ANSI "clear screen" code.
|
protected boolean |
complete()
Use the completers to modify the buffer with the appropriate completions.
|
boolean |
delete()
Issue a delete.
|
void |
drawLine()
Output put the prompt + the current buffer
|
protected String |
expandEvents(String str)
Expand event designator such as !!, !#, !3, etc...
|
protected void |
finalize()
Shuts down the ConsoleReader if the JVM attempts to clean it up.
|
void |
flush()
Flush the console output stream.
|
int |
getAutoprintThreshold() |
boolean |
getBellEnabled()
Get whether the console bell is enabled
|
String |
getCommentBegin() |
Collection<Completer> |
getCompleters()
Returns an unmodifiable list of all the completers.
|
CompletionHandler |
getCompletionHandler() |
CursorBuffer |
getCursorBuffer() |
Character |
getEchoCharacter()
Returns the echo character.
|
boolean |
getExpandEvents() |
boolean |
getHandleUserInterrupt()
Get whether user interrupt handling is enabled
|
History |
getHistory() |
InputStream |
getInput() |
String |
getKeyMap()
Returns the name of the current key mapping.
|
KeyMap |
getKeys() |
Writer |
getOutput() |
String |
getPrompt() |
Terminal |
getTerminal() |
boolean |
isHistoryEnabled()
Whether or not to add new commands to the history buffer.
|
boolean |
isKeyMap(String name) |
boolean |
isPaginationEnabled()
Whether to use pagination when the number of rows of candidates exceeds the height of the terminal.
|
boolean |
killLine()
Kill the buffer ahead of the current cursor position.
|
int |
moveCursor(int num)
Move the cursor where characters.
|
protected boolean |
moveToEnd() |
boolean |
paste()
Paste the contents of the clipboard into the console buffer
|
void |
print(CharSequence s)
Output the specified string to the output stream (but not the buffer).
|
void |
printColumns(Collection<? extends CharSequence> items)
Output the specified
Collection in proper columns. |
protected void |
printCompletionCandidates() |
void |
println()
Output a platform-dependant newline.
|
void |
println(CharSequence s) |
void |
printSearchStatus(String searchTerm,
String match) |
void |
putString(CharSequence str)
Write out the specified string to the buffer and the output stream.
|
int |
readCharacter()
Read a character from the console.
|
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). |
void |
redrawLine()
Clear the line and redraw it.
|
boolean |
removeCompleter(Completer completer)
Remove the specified
Completer from the list of handlers for tab-completion. |
boolean |
replace(int num,
String replacement) |
protected boolean |
resetLine()
Erase the current line.
|
void |
resetPromptLine(String prompt,
String buffer,
int cursorDest)
Erases the current line with the existing prompt, then redraws the line
with the provided prompt and buffer
|
void |
restoreLine(String originalPrompt,
int cursorDest) |
int |
searchBackwards(String searchTerm)
Search backwards in history from the current position.
|
int |
searchBackwards(String searchTerm,
int startIndex)
Search backward in history from a given position.
|
int |
searchBackwards(String searchTerm,
int startIndex,
boolean startsWith) |
void |
setAutoprintThreshold(int threshold) |
void |
setBellEnabled(boolean enabled)
Set whether the console bell is enabled.
|
void |
setCommentBegin(String commentBegin)
Sets the string that will be used to start a comment when the
insert-comment key is struck.
|
void |
setCompletionHandler(CompletionHandler handler) |
boolean |
setCursorPosition(int position)
Move the cursor position to the specified absolute index.
|
void |
setEchoCharacter(Character c)
Set the echo character.
|
void |
setExpandEvents(boolean expand) |
void |
setHandleUserInterrupt(boolean enabled)
Set whether user interrupts (ctrl-C) are handled by having JLine
throw
UserInterruptException from readLine() . |
void |
setHistory(History history) |
void |
setHistoryEnabled(boolean enabled)
Whether or not to add new commands to the history buffer.
|
boolean |
setKeyMap(String name)
Sets the current keymap by name.
|
void |
setPaginationEnabled(boolean enabled)
Whether to use pagination when the number of rows of candidates exceeds the height of the terminal.
|
void |
setParenBlinkTimeout(int timeout) |
void |
setPrompt(String prompt) |
void |
shutdown()
Shuts the console reader down.
|
public static final String JLINE_NOBELL
public static final String JLINE_ESC_TIMEOUT
public static final String JLINE_INPUTRC
public static final String INPUT_RC
public static final String DEFAULT_INPUT_RC
public static final char BACKSPACE
public static final char RESET_LINE
public static final char KEYBOARD_BELL
public static final char NULL_MASK
public static final int TAB_WIDTH
public static final String JLINE_COMPLETION_THRESHOLD
public static final String CR
public ConsoleReader() throws IOException
IOException
public ConsoleReader(InputStream in, OutputStream out) throws IOException
IOException
public ConsoleReader(InputStream in, OutputStream out, Terminal term) throws IOException
IOException
public ConsoleReader(@Nullable String appName, InputStream in, OutputStream out, @Nullable Terminal term) throws IOException
IOException
public ConsoleReader(@Nullable String appName, InputStream in, OutputStream out, @Nullable Terminal term, @Nullable String encoding) throws IOException
IOException
public KeyMap getKeys()
public void shutdown()
protected void finalize() throws Throwable
public InputStream getInput()
public Writer getOutput()
public Terminal getTerminal()
public CursorBuffer getCursorBuffer()
public void setExpandEvents(boolean expand)
public boolean getExpandEvents()
public void setBellEnabled(boolean enabled)
enabled
- true if enabled; false otherwisepublic boolean getBellEnabled()
public void setHandleUserInterrupt(boolean enabled)
UserInterruptException
from readLine()
.
Otherwise, the JVM will handle SIGINT
as normal, which
usually causes it to exit. The default is false
.public boolean getHandleUserInterrupt()
public void setCommentBegin(String commentBegin)
commentBegin
- The begin comment string.public String getCommentBegin()
public void setPrompt(String prompt)
public String getPrompt()
public void setEchoCharacter(Character c)
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.
c
- the character to echo to the console in place of the typed character.public Character getEchoCharacter()
protected final boolean resetLine() throws IOException
IOException
public final boolean setCursorPosition(int position) throws IOException
IOException
public final void drawLine() throws IOException
IOException
public final void redrawLine() throws IOException
IOException
protected String expandEvents(String str) throws IOException
IOException
public final void putString(CharSequence str) throws IOException
IOException
protected void back(int num) throws IOException
IOException
public void flush() throws IOException
IOException
public boolean backspace() throws IOException
IOException
protected boolean moveToEnd() throws IOException
IOException
public void setParenBlinkTimeout(int timeout)
public boolean isKeyMap(String name)
public String accept() throws IOException
IOException
public int moveCursor(int num) throws IOException
num
- If less than 0, move abs(where) to the left, otherwise move where to the right.IOException
public final boolean replace(int num, String replacement)
public final int readCharacter() throws IOException
IOException
public final int readCharacter(char... allowed) throws IOException
IOException
public String readLine() throws IOException
IOException
public String readLine(Character mask) throws IOException
IOException
public String readLine(String prompt) throws IOException
IOException
public boolean setKeyMap(String name)
name
- The name of the keymap to switch topublic String getKeyMap()
setKeyMap(String)
.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 addCompleter(Completer completer)
Completer
to the list of handlers for tab-completion.completer
- the Completer
to addpublic boolean removeCompleter(Completer completer)
Completer
from the list of handlers for tab-completion.completer
- The Completer
to removepublic Collection<Completer> getCompleters()
public void setCompletionHandler(CompletionHandler handler)
public CompletionHandler getCompletionHandler()
protected boolean complete() throws IOException
IOException
protected void printCompletionCandidates() throws IOException
IOException
public void setAutoprintThreshold(int threshold)
threshold
- the number of candidates to print without issuing a warning.public int getAutoprintThreshold()
public void setPaginationEnabled(boolean enabled)
public boolean isPaginationEnabled()
public void setHistory(History history)
public History getHistory()
public void setHistoryEnabled(boolean enabled)
public boolean isHistoryEnabled()
public final void print(CharSequence s) throws IOException
IOException
public final void println(CharSequence s) throws IOException
IOException
public final void println() throws IOException
IOException
public final boolean delete() throws IOException
IOException
public boolean killLine() throws IOException
IOException
public boolean clearScreen() throws IOException
IOException
public void beep() throws IOException
IOException
public boolean paste() throws IOException
IOException
public void addTriggeredAction(char c, ActionListener listener)
public void printColumns(Collection<? extends CharSequence> items) throws IOException
Collection
in proper columns.IOException
public void resetPromptLine(String prompt, String buffer, int cursorDest) throws IOException
prompt
- the new promptbuffer
- the buffer to be drawncursorDest
- where you want the cursor set when the line has been drawn.
-1 for end of line.IOException
public void printSearchStatus(String searchTerm, String match) throws IOException
IOException
public void restoreLine(String originalPrompt, int cursorDest) throws IOException
IOException
public int searchBackwards(String searchTerm, int startIndex)
searchTerm
- substring to search for.startIndex
- the index from which on to searchpublic int searchBackwards(String searchTerm)
searchTerm
- substring to search for.public int searchBackwards(String searchTerm, int startIndex, boolean startsWith)
Copyright © 2015. All Rights Reserved.