Package jline.console
Class ConsoleReader
java.lang.Object
jline.console.ConsoleReader
- All Implemented Interfaces:
Closeable
,AutoCloseable
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.init()
for convenience
methods for issuing platform-specific setup commands.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static enum
Possible states in which the current readline operation may be in. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate String
private int
The number of tab-completion candidates above which a warning will be prompted before showing all the candidates.static final char
private boolean
private final CursorBuffer
private char
Last character searched for with a vi character searchprivate char
private char
private String
private CompletionHandler
private ConsoleKeys
private boolean
Set to true if the reader should attempt to detect copy-n-paste.private boolean
static final String
private Character
private String
private static final int
private long
private boolean
private boolean
private boolean
private History
private boolean
private NonBlockingInputStream
static final String
private URL
static final String
static final String
static final String
static final String
static final String
static final char
private KillRing
private static final String
private String
private Character
private Thread
static final char
private final StringBuilder
private CursorBuffer
private final Writer
private boolean
private int
private String
private String
private int
private boolean
private static final int
private Reader
private boolean
static final char
private static final ResourceBundle
private int
private StringBuffer
private boolean
private ConsoleReader.State
static final int
private final Terminal2
private String
The vi yank buffer -
Constructor Summary
ConstructorsConstructorDescriptionConsoleReader
(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) -
Method Summary
Modifier and TypeMethodDescriptionprivate void
abort()
accept()
The equivalent of hitting <RET>.boolean
addCompleter
(Completer completer) Add the specifiedCompleter
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.private void
protected void
back
(int num) Move the visual cursor backward without modifying the buffer cursor.boolean
Issue a backspace.private int
backspace
(int num) Issue num backspaces.private int
void
beep()
Issue an audible keyboard bell.private void
beforeReadLine
(String prompt, Character mask) private boolean
private void
clearAhead
(int num, int pos) Clear ahead the specified number of characters without moving the cursor.private int
clearEcho
(int c) Clear the echoed characters for the specified character code.boolean
Clear the screen by issuing the ANSI "clear screen" code.void
close()
Shuts the console reader down.protected boolean
complete()
Use the completers to modify the buffer with the appropriate completions.boolean
delete()
Issue a delete.private boolean
Delete the character at the current position and redraw the remainder of the buffer.private boolean
private boolean
private boolean
private void
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 bufferprotected 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.(package private) final String
Clear the buffer and add its contents to the history.void
flush()
Flush the console output stream.private int
fmtPrint
(CharSequence buff, int cursorPos) Output the specified characters to the output stream without manipulating the current buffer.private int
fmtPrint
(CharSequence buff, int start, int end) private int
fmtPrint
(CharSequence buff, int start, int end, int cursorPos) int
boolean
Get whether the console bell is enabledprivate static int
getBracketType
(char ch) Given a character determines what type of bracket it is (paren, square, curly, or none).Returns an unmodifiable list of all the completers.(package private) int
Returns the echo character.boolean
boolean
Get wether literal next are handled by JLine.boolean
Get whether user interrupt handling is enabledgetInput()
static URL
Retrieve the URL for the inputrc configuration file in effect.Returns the name of the current key mapping.getKeys()
private void
private String
insertComment
(boolean isViMode) boolean
private static boolean
isDelimiter
(char c) Checks to see if the specified character is a delimiter.boolean
Whether or not to add new commands to the history buffer.private final boolean
boolean
boolean
Whether to use pagination when the number of rows of candidates exceeds the height of the terminal.private static boolean
isWhitespace
(char c) Checks to see if a character is a whitespace character.boolean
killLine()
Kill the buffer ahead of the current cursor position.private static String
Returns the text after the last '\n'.int
moveCursor
(int num) Move the cursor where characters.private void
moveCursorFromTo
(int i0, int i1) private boolean
moveHistory
(boolean next) Move up or down the history tree.private boolean
moveHistory
(boolean next, int count) Used in "vi" mode for argumented history move, to move a specific number of history entries forward or back.private void
moveInternal
(int where) Move the cursor where characters, without checking the current buffer.protected boolean
(package private) int
nextTabStop
(int pos) private boolean
nextWord()
boolean
paste()
Paste the contents of the clipboard into the console bufferprivate boolean
void
Output the specified string to the output stream (but not the buffer).void
printColumns
(Collection<? extends CharSequence> items) Output the specifiedCollection
in proper columns.protected void
void
printForwardSearchStatus
(String searchTerm, String match) void
println()
Output a platform-dependant newline.void
void
printSearchStatus
(String searchTerm, String match) private void
printSearchStatus
(String searchTerm, String match, String searchLabel) void
putString
(CharSequence str) Write out the specified string to the buffer and the output stream.private void
rawPrint
(char c, int num) (package private) final void
rawPrint
(int c) Raw output printing(package private) final void
private void
rawPrintln
(String s) readBinding
(KeyMap keys) Read from the input stream and decode an operation from the key map.int
Read a character from the console.int
readCharacter
(boolean checkForAltKeyCombo) Read a character from the console.int
readCharacter
(boolean checkForAltKeyCombo, char... allowed) int
readCharacter
(char... allowed) readLine()
Read the next line and return the contents of the buffer.Read the next line with the specified character mask.Read a line from the inInputStream
, and return the line (without any trailing newlines).Read a line from the inInputStream
, and return the line (without any trailing newlines).private String
Read a line for unsupported terminals.void
Clear the line and redraw it.boolean
removeCompleter
(Completer completer) Remove the specifiedCompleter
from the list of handlers for tab-completion.protected final boolean
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 buffervoid
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) int
searchForwards
(String searchTerm) Search forwards in history from the current position.int
searchForwards
(String searchTerm, int startIndex) Search forward in history from a given position.int
searchForwards
(String searchTerm, int startIndex, boolean startsWith) void
setAutoprintThreshold
(int threshold) void
setBellEnabled
(boolean enabled) Set whether the console bell is enabled.private void
setBuffer
(CharSequence buffer) private void
Set the current buffer's content to the specifiedString
.private void
setBufferKeepPos
(CharSequence buffer) private void
setBufferKeepPos
(String buffer) 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) void
setCopyPasteDetection
(boolean onoff) Enables or disables copy and paste detection.boolean
setCursorPosition
(int position) Move the cursor position to the specified absolute index.void
Set the echo character.void
setExpandEvents
(boolean expand) void
setHandleLitteralNext
(boolean handleLitteralNext) Set wether literal next are handled by JLine.void
setHandleUserInterrupt
(boolean enabled) Set whether user interrupts (ctrl-C) are handled by having JLine throwUserInterruptException
fromreadLine()
.void
setHistory
(History history) void
setHistoryEnabled
(boolean enabled) Whether or not to add new commands to the history buffer.(package private) void
setInput
(InputStream in) boolean
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
private void
void
shutdown()
Deprecated.private static char
switchCase
(char ch) private boolean
private boolean
transposeChars
(int count) Performs character transpose.private boolean
unixWordRubout
(int count) Deletes to the beginning of the word that the cursor is sitting on.private boolean
private boolean
viChangeCase
(int count) Switches the case of the current character from upper to lower or lower to upper as necessary and advances the cursor one position to the right.private boolean
viChangeChar
(int count, int c) Implements the vi change character command (in move-mode "r" followed by the character to change to).private boolean
viCharSearch
(int count, int invokeChar, int ch) Searches forward of the current position for a character and moves the cursor onto it.private boolean
viDelete
(int count) Deletes the character you are sitting on and sucks the rest of the line in from the right.private Operation
This method is calling while doing a delete-to ("d"), change-to ("c"), or yank-to ("y") and it filters out only those movement operations that are allowable during those operations.private boolean
viDeleteTo
(int startPos, int endPos, boolean isChange) Performs the vi "delete-to" action, deleting characters between a given span of the input line.private boolean
viEndWord
(int count) Implements a close facsimile of the vi end-of-word movement.private boolean
viMatch()
Implements vi style bracket matching ("%" command).private boolean
viNextWord
(int count) This is a close facsimile of the actual vi next word logic.private boolean
viPreviousWord
(int count) This is a close facsimile of the actual vi previous word logic.private boolean
viPut
(int count) Pasts the yank buffer to the right of the current cursor position and moves the cursor to the end of the pasted region.private boolean
viRubout
(int count) Deletes the previous character from the cursor positionprivate int
viSearch
(char searchChar) Implements vi search ("/" or "?").private boolean
viYankTo
(int startPos, int endPos) Implement the "vi" yank-to operation.(package private) int
wcwidth
(int ucs, int pos) (package private) int
wcwidth
(CharSequence str, int pos) (package private) int
wcwidth
(CharSequence str, int start, int end, int pos) boolean
yank()
boolean
yankPop()
-
Field Details
-
JLINE_NOBELL
- See Also:
-
JLINE_ESC_TIMEOUT
- See Also:
-
JLINE_INPUTRC
- See Also:
-
INPUT_RC
- See Also:
-
DEFAULT_INPUT_RC
- See Also:
-
JLINE_EXPAND_EVENTS
- See Also:
-
BACKSPACE
public static final char BACKSPACE- See Also:
-
RESET_LINE
public static final char RESET_LINE- See Also:
-
KEYBOARD_BELL
public static final char KEYBOARD_BELL- See Also:
-
NULL_MASK
public static final char NULL_MASK- See Also:
-
TAB_WIDTH
public static final int TAB_WIDTH- See Also:
-
resources
-
ESCAPE
private static final int ESCAPE- See Also:
-
READ_EXPIRED
private static final int READ_EXPIRED- See Also:
-
terminal
-
out
-
buf
-
cursorOk
private boolean cursorOk -
prompt
-
promptLen
private int promptLen -
expandEvents
private boolean expandEvents -
bellEnabled
private boolean bellEnabled -
handleUserInterrupt
private boolean handleUserInterrupt -
handleLitteralNext
private boolean handleLitteralNext -
mask
-
echoCharacter
-
originalBuffer
-
searchTerm
-
previousSearchTerm
-
searchIndex
private int searchIndex -
parenBlinkTimeout
private int parenBlinkTimeout -
opBuffer
-
pushBackChar
-
in
-
escapeTimeout
private long escapeTimeout -
reader
-
charSearchChar
private char charSearchCharLast character searched for with a vi character search -
charSearchLastInvokeChar
private char charSearchLastInvokeChar -
charSearchFirstInvokeChar
private char charSearchFirstInvokeChar -
yankBuffer
The vi yank buffer -
killRing
-
encoding
-
quotedInsert
private boolean quotedInsert -
recording
private boolean recording -
macro
-
appName
-
inputrcUrl
-
consoleKeys
-
commentBegin
-
skipLF
private boolean skipLF -
copyPasteDetection
private boolean copyPasteDetectionSet to true if the reader should attempt to detect copy-n-paste. The effect of this that an attempt is made to detect if tab is quickly followed by another character, then it is assumed that the tab was a literal tab as part of a copy-and-paste operation and is inserted as such. -
state
-
JLINE_COMPLETION_THRESHOLD
- See Also:
-
completers
-
completionHandler
-
autoprintThreshold
private int autoprintThresholdThe number of tab-completion candidates above which a warning will be prompted before showing all the candidates. -
paginationEnabled
private boolean paginationEnabled -
history
-
historyEnabled
private boolean historyEnabled -
LINE_SEPARATOR
-
maskThread
-
-
Constructor Details
-
ConsoleReader
- Throws:
IOException
-
ConsoleReader
- Throws:
IOException
-
ConsoleReader
- Throws:
IOException
-
ConsoleReader
public ConsoleReader(@Nullable String appName, InputStream in, OutputStream out, @Nullable Terminal term) throws IOException - Throws:
IOException
-
ConsoleReader
public ConsoleReader(@Nullable String appName, InputStream in, OutputStream out, @Nullable Terminal term, @Nullable String encoding) throws IOException - Throws:
IOException
-
-
Method Details
-
setupSigCont
private void setupSigCont() -
getInputRc
Retrieve the URL for the inputrc configuration file in effect. Intended use is for instantiating ConsoleKeys, to read inputrc variables.- Throws:
IOException
-
getKeys
-
setInput
- Throws:
IOException
-
close
public void close()Shuts the console reader down. This method should be called when you have completed using the reader as it shuts down and cleans up resources that would otherwise be "leaked".- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
-
shutdown
Deprecated.Useclose()
instead.Shuts the console reader down. The same asclose()
. -
finalize
Shuts down the ConsoleReader if the JVM attempts to clean it up. -
getInput
-
getOutput
-
getTerminal
-
getCursorBuffer
-
setExpandEvents
public void setExpandEvents(boolean expand) -
getExpandEvents
public boolean getExpandEvents() -
setCopyPasteDetection
public void setCopyPasteDetection(boolean onoff) Enables or disables copy and paste detection. The effect of enabling this this setting is that when a tab is received immediately followed by another character, the tab will not be treated as a completion, but as a tab literal.- Parameters:
onoff
- true if detection is enabled
-
isCopyPasteDetectionEnabled
public boolean isCopyPasteDetectionEnabled()- Returns:
- true if copy and paste detection is enabled.
-
setBellEnabled
public void setBellEnabled(boolean enabled) Set whether the console bell is enabled.- Parameters:
enabled
- true if enabled; false otherwise- Since:
- 2.7
-
getBellEnabled
public boolean getBellEnabled()Get whether the console bell is enabled- Returns:
- true if enabled; false otherwise
- Since:
- 2.7
-
setHandleUserInterrupt
public void setHandleUserInterrupt(boolean enabled) Set whether user interrupts (ctrl-C) are handled by having JLine throwUserInterruptException
fromreadLine()
. Otherwise, the JVM will handleSIGINT
as normal, which usually causes it to exit. The default isfalse
.- Since:
- 2.10
-
getHandleUserInterrupt
public boolean getHandleUserInterrupt()Get whether user interrupt handling is enabled- Returns:
- true if enabled; false otherwise
- Since:
- 2.10
-
setHandleLitteralNext
public void setHandleLitteralNext(boolean handleLitteralNext) Set wether literal next are handled by JLine.- Since:
- 2.13
-
getHandleLitteralNext
public boolean getHandleLitteralNext()Get wether literal next are handled by JLine.- Since:
- 2.13
-
setCommentBegin
Sets the string that will be used to start a comment when the insert-comment key is struck.- Parameters:
commentBegin
- The begin comment string.- Since:
- 2.7
-
getCommentBegin
- Returns:
- the string that will be used to start a comment when the insert-comment key is struck.
- Since:
- 2.7
-
setPrompt
-
getPrompt
-
setEchoCharacter
Set the echo character. For example, to have "*" entered when a password is typed:myConsoleReader.setEchoCharacter(new Character('*'));
Setting the character tonull
will restore normal character echoing. Setting the character toCharacter.valueOf(0)
will cause nothing to be echoed.- Parameters:
c
- the character to echo to the console in place of the typed character.
-
getEchoCharacter
Returns the echo character. -
resetLine
Erase the current line.- Returns:
- false if we failed (e.g., the buffer was empty)
- Throws:
IOException
-
wcwidth
-
wcwidth
-
wcwidth
int wcwidth(int ucs, int pos) -
nextTabStop
int nextTabStop(int pos) -
getCursorPosition
int getCursorPosition() -
lastLine
Returns the text after the last '\n'. prompt is returned if no '\n' characters are present. null is returned if prompt is null. -
setCursorPosition
Move the cursor position to the specified absolute index.- Throws:
IOException
-
setBuffer
Set the current buffer's content to the specifiedString
. The visual console will be modified to show the current buffer.- Parameters:
buffer
- the new contents of the buffer.- Throws:
IOException
-
setBuffer
- Throws:
IOException
-
setBufferKeepPos
- Throws:
IOException
-
setBufferKeepPos
- Throws:
IOException
-
drawLine
Output put the prompt + the current buffer- Throws:
IOException
-
redrawLine
Clear the line and redraw it.- Throws:
IOException
-
finishBuffer
Clear the buffer and add its contents to the history.- Returns:
- the former contents of the buffer.
- Throws:
IOException
-
expandEvents
Expand event designator such as !!, !#, !3, etc... See http://www.gnu.org/software/bash/manual/html_node/Event-Designators.html- Throws:
IOException
-
putString
Write out the specified string to the buffer and the output stream.- Throws:
IOException
-
drawBuffer
Redraw the rest of the buffer from the cursor onwards. This is necessary for inserting text into the buffer.- Parameters:
clear
- the number of characters to clear after the end of the buffer- Throws:
IOException
-
drawBuffer
Redraw the rest of the buffer from the cursor onwards. This is necessary for inserting text into the buffer.- Throws:
IOException
-
clearAhead
Clear ahead the specified number of characters without moving the cursor.- Parameters:
num
- the number of characters to clearpos
- the current screen cursor position- Throws:
IOException
-
back
Move the visual cursor backward without modifying the buffer cursor.- Throws:
IOException
-
flush
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 immediately.- Throws:
IOException
-
backspaceAll
- Throws:
IOException
-
backspace
Issue num backspaces.- Returns:
- the number of characters backed up
- Throws:
IOException
-
backspace
Issue a backspace.- Returns:
- true if successful
- Throws:
IOException
-
moveToEnd
- Throws:
IOException
-
deleteCurrentCharacter
Delete the character at the current position and redraw the remainder of the buffer.- Throws:
IOException
-
viDeleteChangeYankToRemap
This method is calling while doing a delete-to ("d"), change-to ("c"), or yank-to ("y") and it filters out only those movement operations that are allowable during those operations. Any operation that isn't allow drops you back into movement mode.- Parameters:
op
- The incoming operation to remap- Returns:
- The remaped operation
-
viRubout
Deletes the previous character from the cursor position- Parameters:
count
- number of times to do it.- Returns:
- true if it was done.
- Throws:
IOException
-
viDelete
Deletes the character you are sitting on and sucks the rest of the line in from the right.- Parameters:
count
- Number of times to perform the operation.- Returns:
- true if its works, false if it didn't
- Throws:
IOException
-
viChangeCase
Switches the case of the current character from upper to lower or lower to upper as necessary and advances the cursor one position to the right.- Parameters:
count
- The number of times to repeat- Returns:
- true if it completed successfully, false if not all case changes could be completed.
- Throws:
IOException
-
viChangeChar
Implements the vi change character command (in move-mode "r" followed by the character to change to).- Parameters:
count
- Number of times to perform the actionc
- The character to change to- Returns:
- Whether or not there were problems encountered
- Throws:
IOException
-
viPreviousWord
This is a close facsimile of the actual vi previous word logic. In actual vi words are determined by boundaries of identity characterse. This logic is a bit more simple and simply looks at white space or digits or characters. It should be revised at some point.- Parameters:
count
- number of iterations- Returns:
- true if the move was successful, false otherwise
- Throws:
IOException
-
viDeleteTo
Performs the vi "delete-to" action, deleting characters between a given span of the input line.- Parameters:
startPos
- The start positionendPos
- The end position.isChange
- If true, then the delete is part of a change operationg (e.g. "c$" is change-to-end-of line, so we first must delete to end of line to start the change- Returns:
- true if it succeeded, false otherwise
- Throws:
IOException
-
viYankTo
Implement the "vi" yank-to operation. This operation allows you to yank the contents of the current line based upon a move operation, for exaple "yw" yanks the current word, "3yw" yanks 3 words, etc.- Parameters:
startPos
- The starting position from which to yankendPos
- The ending position to which to yank- Returns:
- true if the yank succeeded
- Throws:
IOException
-
viPut
Pasts the yank buffer to the right of the current cursor position and moves the cursor to the end of the pasted region.- Parameters:
count
- Number of times to perform the operation.- Returns:
- true if it worked, false otherwise
- Throws:
IOException
-
viCharSearch
Searches forward of the current position for a character and moves the cursor onto it.- Parameters:
count
- Number of times to repeat the process.ch
- The character to search for- Returns:
- true if the char was found, false otherwise
- Throws:
IOException
-
switchCase
private static char switchCase(char ch) -
isInViMoveOperationState
private final boolean isInViMoveOperationState()- Returns:
- true if line reader is in the middle of doing a change-to delete-to or yank-to.
-
viNextWord
This is a close facsimile of the actual vi next word logic. As with viPreviousWord() this probably needs to be improved at some point.- Parameters:
count
- number of iterations- Returns:
- true if the move was successful, false otherwise
- Throws:
IOException
-
viEndWord
Implements a close facsimile of the vi end-of-word movement. If the character is on white space, it takes you to the end of the next word. If it is on the last character of a word it takes you to the next of the next word. Any other character of a word, takes you to the end of the current word.- Parameters:
count
- Number of times to repeat the action- Returns:
- true if it worked.
- Throws:
IOException
-
previousWord
- Throws:
IOException
-
nextWord
- Throws:
IOException
-
unixWordRubout
Deletes to the beginning of the word that the cursor is sitting on. If the cursor is on white-space, it deletes that and to the beginning of the word before it. If the user is not on a word or whitespace it deletes up to the end of the previous word.- Parameters:
count
- Number of times to perform the operation- Returns:
- true if it worked, false if you tried to delete too many words
- Throws:
IOException
-
insertComment
- Throws:
IOException
-
viSearch
Implements vi search ("/" or "?").- Throws:
IOException
-
setParenBlinkTimeout
public void setParenBlinkTimeout(int timeout) -
insertClose
- Throws:
IOException
-
viMatch
Implements vi style bracket matching ("%" command). The matching bracket for the current bracket type that you are sitting on is matched. The logic works like so:- Returns:
- true if it worked, false if the cursor was not on a bracket character or if there was no matching bracket.
- Throws:
IOException
-
getBracketType
private static int getBracketType(char ch) Given a character determines what type of bracket it is (paren, square, curly, or none).- Parameters:
ch
- The character to check- Returns:
- 1 is square, 2 curly, 3 parent, or zero for none. The value will be negated if it is the closing form of the bracket.
-
deletePreviousWord
- Throws:
IOException
-
deleteNextWord
- Throws:
IOException
-
capitalizeWord
- Throws:
IOException
-
upCaseWord
- Throws:
IOException
-
downCaseWord
- Throws:
IOException
-
transposeChars
Performs character transpose. The character prior to the cursor and the character under the cursor are swapped and the cursor is advanced one character unless you are already at the end of the line.- Parameters:
count
- The number of times to perform the transpose- Returns:
- true if the operation succeeded, false otherwise (e.g. transpose cannot happen at the beginning of the line).
- Throws:
IOException
-
isKeyMap
-
accept
The equivalent of hitting <RET>. The line is considered complete and is returned.- Returns:
- The completed line of text.
- Throws:
IOException
-
abort
- Throws:
IOException
-
moveCursor
Move the cursor where characters.- Parameters:
num
- If less than 0, move abs(where) to the left, otherwise move where to the right.- Returns:
- The number of spaces we moved
- Throws:
IOException
-
moveInternal
Move the cursor where characters, without checking the current buffer.- Parameters:
where
- the number of characters to move to the right or left.- Throws:
IOException
-
moveCursorFromTo
- Throws:
IOException
-
readCharacter
Read a character from the console.- Returns:
- the character, or -1 if an EOF is received.
- Throws:
IOException
-
readCharacter
Read a character from the console. If boolean parameter is "true", it will check whether the keystroke was an "alt-" key combination, and if so add 1000 to the value returned. Better way...?- Returns:
- the character, or -1 if an EOF is received.
- Throws:
IOException
-
clearEcho
Clear the echoed characters for the specified character code.- Throws:
IOException
-
readCharacter
- Throws:
IOException
-
readCharacter
- Throws:
IOException
-
readBinding
Read from the input stream and decode an operation from the key map. The input stream will be read character by character until a matching binding can be found. Characters that can't possibly be matched to any binding will be discarded.- Parameters:
keys
- the KeyMap to use for decoding the input stream- Returns:
- the decoded binding or
null
if the end of stream has been reached - Throws:
IOException
-
getLastBinding
-
readLine
Read the next line and return the contents of the buffer.- Throws:
IOException
-
readLine
Read the next line with the specified character mask. If null, then characters will be echoed. If 0, then no characters will be echoed.- Throws:
IOException
-
readLine
- Throws:
IOException
-
readLine
Read a line from the inInputStream
, and return the line (without any trailing newlines).- Parameters:
prompt
- The prompt to issue to the console, may be null.- Returns:
- A line that is read from the terminal, or null if there was null input (e.g., CTRL-D was pressed).
- Throws:
IOException
-
setKeyMap
Sets the current keymap by name. Supported keymaps are "emacs", "vi-insert", "vi-move".- Parameters:
name
- The name of the keymap to switch to- Returns:
- true if the keymap was set, or false if the keymap is not recognized.
-
getKeyMap
Returns the name of the current key mapping.- Returns:
- the name of the key mapping. This will be the canonical name
of the current mode of the key map and may not reflect the name that
was used with
setKeyMap(String)
.
-
readLine
Read a line from the inInputStream
, and return the line (without any trailing newlines).- Parameters:
prompt
- The prompt to issue to the console, may be null.- Returns:
- A line that is read from the terminal, or null if there was null input (e.g., CTRL-D was pressed).
- Throws:
IOException
-
readLineSimple
Read a line for unsupported terminals.- Throws:
IOException
-
addCompleter
Add the specifiedCompleter
to the list of handlers for tab-completion.- Parameters:
completer
- theCompleter
to add- Returns:
- true if it was successfully added
-
removeCompleter
Remove the specifiedCompleter
from the list of handlers for tab-completion.- Parameters:
completer
- TheCompleter
to remove- Returns:
- True if it was successfully removed
-
getCompleters
Returns an unmodifiable list of all the completers. -
setCompletionHandler
-
getCompletionHandler
-
complete
Use the completers to modify the buffer with the appropriate completions.- Returns:
- true if successful
- Throws:
IOException
-
printCompletionCandidates
- Throws:
IOException
-
setAutoprintThreshold
public void setAutoprintThreshold(int threshold) - Parameters:
threshold
- the number of candidates to print without issuing a warning.
-
getAutoprintThreshold
public int getAutoprintThreshold()- Returns:
- the number of candidates to print without issuing a warning.
-
setPaginationEnabled
public void setPaginationEnabled(boolean enabled) Whether to use pagination when the number of rows of candidates exceeds the height of the terminal. -
isPaginationEnabled
public boolean isPaginationEnabled()Whether to use pagination when the number of rows of candidates exceeds the height of the terminal. -
setHistory
-
getHistory
-
setHistoryEnabled
public void setHistoryEnabled(boolean enabled) Whether or not to add new commands to the history buffer. -
isHistoryEnabled
public boolean isHistoryEnabled()Whether or not to add new commands to the history buffer. -
moveHistory
Used in "vi" mode for argumented history move, to move a specific number of history entries forward or back.- Parameters:
next
- If true, move forwardcount
- The number of entries to move- Returns:
- true if the move was successful
- Throws:
IOException
-
moveHistory
Move up or down the history tree.- Throws:
IOException
-
fmtPrint
Output the specified characters to the output stream without manipulating the current buffer.- Throws:
IOException
-
fmtPrint
- Throws:
IOException
-
fmtPrint
- Throws:
IOException
-
print
Output the specified string to the output stream (but not the buffer).- Throws:
IOException
-
println
- Throws:
IOException
-
println
Output a platform-dependant newline.- Throws:
IOException
-
rawPrint
Raw output printing- Throws:
IOException
-
rawPrint
- Throws:
IOException
-
rawPrint
- Throws:
IOException
-
rawPrintln
- Throws:
IOException
-
delete
Issue a delete.- Returns:
- true if successful
- Throws:
IOException
-
killLine
Kill the buffer ahead of the current cursor position.- Returns:
- true if successful
- Throws:
IOException
-
yank
- Throws:
IOException
-
yankPop
- Throws:
IOException
-
clearScreen
Clear the screen by issuing the ANSI "clear screen" code.- Throws:
IOException
-
beep
Issue an audible keyboard bell.- Throws:
IOException
-
paste
Paste the contents of the clipboard into the console buffer- Returns:
- true if clipboard contents pasted
- Throws:
IOException
-
addTriggeredAction
Adding a triggered Action allows to give another curse of action if a character passed the pre-processing. Say you want to close the application if the user enter q. addTriggerAction('q', new ActionListener(){ System.exit(0); }); would do the trick. -
printColumns
Output the specifiedCollection
in proper columns.- Throws:
IOException
-
beforeReadLine
-
afterReadLine
private void afterReadLine() -
resetPromptLine
Erases the current line with the existing prompt, then redraws the line with the provided prompt and buffer- Parameters:
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.- Throws:
IOException
-
printSearchStatus
- Throws:
IOException
-
printForwardSearchStatus
- Throws:
IOException
-
printSearchStatus
private void printSearchStatus(String searchTerm, String match, String searchLabel) throws IOException - Throws:
IOException
-
restoreLine
- Throws:
IOException
-
searchBackwards
Search backward in history from a given position.- Parameters:
searchTerm
- substring to search for.startIndex
- the index from which on to search- Returns:
- index where this substring has been found, or -1 else.
-
searchBackwards
Search backwards in history from the current position.- Parameters:
searchTerm
- substring to search for.- Returns:
- index where the substring has been found, or -1 else.
-
searchBackwards
-
searchForwards
Search forward in history from a given position.- Parameters:
searchTerm
- substring to search for.startIndex
- the index from which on to search- Returns:
- index where this substring has been found, or -1 else.
-
searchForwards
Search forwards in history from the current position.- Parameters:
searchTerm
- substring to search for.- Returns:
- index where the substring has been found, or -1 else.
-
searchForwards
-
isDelimiter
private static 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.- Parameters:
c
- The character to test- Returns:
- True if it is a delimiter
-
isWhitespace
private static boolean isWhitespace(char c) Checks to see if a character is a whitespace character. Currently this delegates toCharacter.isWhitespace(char)
, however eventually it should be hooked up so that the definition of whitespace can be configured, as readline does.- Parameters:
c
- The character to check- Returns:
- true if the character is a whitespace
-
tputs
- Throws:
IOException
-
close()
instead.