Package jline.console
Class ConsoleReader
- java.lang.Object
-
- jline.console.ConsoleReader
-
- All Implemented Interfaces:
java.io.Closeable,java.lang.AutoCloseable
public class ConsoleReader extends java.lang.Object implements java.io.CloseableA 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. SeeTerminal.init()for convenience methods for issuing platform-specific setup commands.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static classConsoleReader.StatePossible states in which the current readline operation may be in.
-
Field Summary
Fields Modifier and Type Field Description private java.lang.StringappNameprivate intautoprintThresholdThe number of tab-completion candidates above which a warning will be prompted before showing all the candidates.static charBACKSPACEprivate booleanbellEnabledprivate CursorBufferbufprivate charcharSearchCharLast character searched for with a vi character searchprivate charcharSearchFirstInvokeCharprivate charcharSearchLastInvokeCharprivate java.lang.StringcommentBeginprivate java.util.List<Completer>completersprivate CompletionHandlercompletionHandlerprivate ConsoleKeysconsoleKeysprivate booleancopyPasteDetectionSet to true if the reader should attempt to detect copy-n-paste.private booleancursorOkstatic java.lang.StringDEFAULT_INPUT_RCprivate java.lang.CharacterechoCharacterprivate java.lang.Stringencodingprivate static intESCAPEprivate longescapeTimeoutprivate booleanexpandEventsprivate booleanhandleLitteralNextprivate booleanhandleUserInterruptprivate Historyhistoryprivate booleanhistoryEnabledprivate NonBlockingInputStreaminstatic java.lang.StringINPUT_RCprivate java.net.URLinputrcUrlstatic java.lang.StringJLINE_COMPLETION_THRESHOLDstatic java.lang.StringJLINE_ESC_TIMEOUTstatic java.lang.StringJLINE_EXPAND_EVENTSstatic java.lang.StringJLINE_INPUTRCstatic java.lang.StringJLINE_NOBELLstatic charKEYBOARD_BELLprivate KillRingkillRingprivate static java.lang.StringLINE_SEPARATORprivate java.lang.Stringmacroprivate java.lang.Charactermaskprivate java.lang.ThreadmaskThreadstatic charNULL_MASKprivate java.lang.StringBuilderopBufferprivate CursorBufferoriginalBufferprivate java.io.Writeroutprivate booleanpaginationEnabledprivate intparenBlinkTimeoutprivate java.lang.StringpreviousSearchTermprivate java.lang.Stringpromptprivate intpromptLenprivate java.util.Stack<java.lang.Character>pushBackCharprivate booleanquotedInsertprivate static intREAD_EXPIREDprivate java.io.Readerreaderprivate booleanrecordingstatic charRESET_LINEprivate static java.util.ResourceBundleresourcesprivate intsearchIndexprivate java.lang.StringBuffersearchTermprivate booleanskipLFprivate ConsoleReader.Statestatestatic intTAB_WIDTHprivate Terminal2terminalprivate java.lang.StringyankBufferThe vi yank buffer
-
Constructor Summary
Constructors Constructor Description ConsoleReader()ConsoleReader(java.io.InputStream in, java.io.OutputStream out)ConsoleReader(java.io.InputStream in, java.io.OutputStream out, Terminal term)ConsoleReader(java.lang.String appName, java.io.InputStream in, java.io.OutputStream out, Terminal term)ConsoleReader(java.lang.String appName, java.io.InputStream in, java.io.OutputStream out, Terminal term, java.lang.String encoding)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description private voidabort()java.lang.Stringaccept()The equivalent of hitting <RET>.booleanaddCompleter(Completer completer)Add the specifiedCompleterto the list of handlers for tab-completion.voidaddTriggeredAction(char c, java.awt.event.ActionListener listener)Adding a triggered Action allows to give another curse of action if a character passed the pre-processing.private voidafterReadLine()protected voidback(int num)Move the visual cursor backward without modifying the buffer cursor.booleanbackspace()Issue a backspace.private intbackspace(int num)Issue num backspaces.private intbackspaceAll()voidbeep()Issue an audible keyboard bell.private voidbeforeReadLine(java.lang.String prompt, java.lang.Character mask)private booleancapitalizeWord()private voidclearAhead(int num, int pos)Clear ahead the specified number of characters without moving the cursor.private intclearEcho(int c)Clear the echoed characters for the specified character code.booleanclearScreen()Clear the screen by issuing the ANSI "clear screen" code.voidclose()Shuts the console reader down.protected booleancomplete()Use the completers to modify the buffer with the appropriate completions.booleandelete()Issue a delete.private booleandeleteCurrentCharacter()Delete the character at the current position and redraw the remainder of the buffer.private booleandeleteNextWord()private booleandeletePreviousWord()private booleandownCaseWord()private voiddrawBuffer()Redraw the rest of the buffer from the cursor onwards.private voiddrawBuffer(int clear)Redraw the rest of the buffer from the cursor onwards.voiddrawLine()Output put the prompt + the current bufferprotected java.lang.StringexpandEvents(java.lang.String str)Expand event designator such as !!, !#, !3, etc...protected voidfinalize()Shuts down the ConsoleReader if the JVM attempts to clean it up.(package private) java.lang.StringfinishBuffer()Clear the buffer and add its contents to the history.voidflush()Flush the console output stream.private intfmtPrint(java.lang.CharSequence buff, int cursorPos)Output the specified characters to the output stream without manipulating the current buffer.private intfmtPrint(java.lang.CharSequence buff, int start, int end)private intfmtPrint(java.lang.CharSequence buff, int start, int end, int cursorPos)intgetAutoprintThreshold()booleangetBellEnabled()Get whether the console bell is enabledprivate static intgetBracketType(char ch)Given a character determines what type of bracket it is (paren, square, curly, or none).java.lang.StringgetCommentBegin()java.util.Collection<Completer>getCompleters()Returns an unmodifiable list of all the completers.CompletionHandlergetCompletionHandler()CursorBuffergetCursorBuffer()(package private) intgetCursorPosition()java.lang.CharactergetEchoCharacter()Returns the echo character.booleangetExpandEvents()booleangetHandleLitteralNext()Get wether literal next are handled by JLine.booleangetHandleUserInterrupt()Get whether user interrupt handling is enabledHistorygetHistory()java.io.InputStreamgetInput()static java.net.URLgetInputRc()Retrieve the URL for the inputrc configuration file in effect.java.lang.StringgetKeyMap()Returns the name of the current key mapping.KeyMapgetKeys()java.lang.StringgetLastBinding()java.io.WritergetOutput()java.lang.StringgetPrompt()TerminalgetTerminal()private voidinsertClose(java.lang.String s)private java.lang.StringinsertComment(boolean isViMode)booleanisCopyPasteDetectionEnabled()private static booleanisDelimiter(char c)Checks to see if the specified character is a delimiter.booleanisHistoryEnabled()Whether or not to add new commands to the history buffer.private booleanisInViMoveOperationState()booleanisKeyMap(java.lang.String name)booleanisPaginationEnabled()Whether to use pagination when the number of rows of candidates exceeds the height of the terminal.private static booleanisWhitespace(char c)Checks to see if a character is a whitespace character.booleankillLine()Kill the buffer ahead of the current cursor position.private static java.lang.StringlastLine(java.lang.String str)Returns the text after the last '\n'.intmoveCursor(int num)Move the cursor where characters.private voidmoveCursorFromTo(int i0, int i1)private booleanmoveHistory(boolean next)Move up or down the history tree.private booleanmoveHistory(boolean next, int count)Used in "vi" mode for argumented history move, to move a specific number of history entries forward or back.private voidmoveInternal(int where)Move the cursor where characters, without checking the current buffer.protected booleanmoveToEnd()(package private) intnextTabStop(int pos)private booleannextWord()booleanpaste()Paste the contents of the clipboard into the console bufferprivate booleanpreviousWord()voidprint(java.lang.CharSequence s)Output the specified string to the output stream (but not the buffer).voidprintColumns(java.util.Collection<? extends java.lang.CharSequence> items)Output the specifiedCollectionin proper columns.protected voidprintCompletionCandidates()voidprintForwardSearchStatus(java.lang.String searchTerm, java.lang.String match)voidprintln()Output a platform-dependant newline.voidprintln(java.lang.CharSequence s)voidprintSearchStatus(java.lang.String searchTerm, java.lang.String match)private voidprintSearchStatus(java.lang.String searchTerm, java.lang.String match, java.lang.String searchLabel)voidputString(java.lang.CharSequence str)Write out the specified string to the buffer and the output stream.private voidrawPrint(char c, int num)(package private) voidrawPrint(int c)Raw output printing(package private) voidrawPrint(java.lang.String str)private voidrawPrintln(java.lang.String s)java.lang.ObjectreadBinding(KeyMap keys)Read from the input stream and decode an operation from the key map.intreadCharacter()Read a character from the console.intreadCharacter(boolean checkForAltKeyCombo)Read a character from the console.intreadCharacter(boolean checkForAltKeyCombo, char... allowed)intreadCharacter(char... allowed)java.lang.StringreadLine()Read the next line and return the contents of the buffer.java.lang.StringreadLine(java.lang.Character mask)Read the next line with the specified character mask.java.lang.StringreadLine(java.lang.String prompt)java.lang.StringreadLine(java.lang.String prompt, java.lang.Character mask)Read a line from the inInputStream, and return the line (without any trailing newlines).java.lang.StringreadLine(java.lang.String prompt, java.lang.Character mask, java.lang.String buffer)Read a line from the inInputStream, and return the line (without any trailing newlines).private java.lang.StringreadLineSimple()Read a line for unsupported terminals.voidredrawLine()Clear the line and redraw it.booleanremoveCompleter(Completer completer)Remove the specifiedCompleterfrom the list of handlers for tab-completion.protected booleanresetLine()Erase the current line.voidresetPromptLine(java.lang.String prompt, java.lang.String buffer, int cursorDest)Erases the current line with the existing prompt, then redraws the line with the provided prompt and buffervoidrestoreLine(java.lang.String originalPrompt, int cursorDest)intsearchBackwards(java.lang.String searchTerm)Search backwards in history from the current position.intsearchBackwards(java.lang.String searchTerm, int startIndex)Search backward in history from a given position.intsearchBackwards(java.lang.String searchTerm, int startIndex, boolean startsWith)intsearchForwards(java.lang.String searchTerm)Search forwards in history from the current position.intsearchForwards(java.lang.String searchTerm, int startIndex)Search forward in history from a given position.intsearchForwards(java.lang.String searchTerm, int startIndex, boolean startsWith)voidsetAutoprintThreshold(int threshold)voidsetBellEnabled(boolean enabled)Set whether the console bell is enabled.private voidsetBuffer(java.lang.CharSequence buffer)private voidsetBuffer(java.lang.String buffer)Set the current buffer's content to the specifiedString.private voidsetBufferKeepPos(java.lang.CharSequence buffer)private voidsetBufferKeepPos(java.lang.String buffer)voidsetCommentBegin(java.lang.String commentBegin)Sets the string that will be used to start a comment when the insert-comment key is struck.voidsetCompletionHandler(CompletionHandler handler)voidsetCopyPasteDetection(boolean onoff)Enables or disables copy and paste detection.booleansetCursorPosition(int position)Move the cursor position to the specified absolute index.voidsetEchoCharacter(java.lang.Character c)Set the echo character.voidsetExpandEvents(boolean expand)voidsetHandleLitteralNext(boolean handleLitteralNext)Set wether literal next are handled by JLine.voidsetHandleUserInterrupt(boolean enabled)Set whether user interrupts (ctrl-C) are handled by having JLine throwUserInterruptExceptionfromreadLine().voidsetHistory(History history)voidsetHistoryEnabled(boolean enabled)Whether or not to add new commands to the history buffer.(package private) voidsetInput(java.io.InputStream in)booleansetKeyMap(java.lang.String name)Sets the current keymap by name.voidsetPaginationEnabled(boolean enabled)Whether to use pagination when the number of rows of candidates exceeds the height of the terminal.voidsetParenBlinkTimeout(int timeout)voidsetPrompt(java.lang.String prompt)private voidsetupSigCont()voidshutdown()Deprecated.Useclose()instead.private static charswitchCase(char ch)private booleantputs(java.lang.String cap, java.lang.Object... params)private booleantransposeChars(int count)Performs character transpose.private booleanunixWordRubout(int count)Deletes to the beginning of the word that the cursor is sitting on.private booleanupCaseWord()private booleanviChangeCase(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 booleanviChangeChar(int count, int c)Implements the vi change character command (in move-mode "r" followed by the character to change to).private booleanviCharSearch(int count, int invokeChar, int ch)Searches forward of the current position for a character and moves the cursor onto it.private booleanviDelete(int count)Deletes the character you are sitting on and sucks the rest of the line in from the right.private OperationviDeleteChangeYankToRemap(Operation op)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 booleanviDeleteTo(int startPos, int endPos, boolean isChange)Performs the vi "delete-to" action, deleting characters between a given span of the input line.private booleanviEndWord(int count)Implements a close facsimile of the vi end-of-word movement.private booleanviMatch()Implements vi style bracket matching ("%" command).private booleanviNextWord(int count)This is a close facsimile of the actual vi next word logic.private booleanviPreviousWord(int count)This is a close facsimile of the actual vi previous word logic.private booleanviPut(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 booleanviRubout(int count)Deletes the previous character from the cursor positionprivate intviSearch(char searchChar)Implements vi search ("/" or "?").private booleanviYankTo(int startPos, int endPos)Implement the "vi" yank-to operation.(package private) intwcwidth(int ucs, int pos)(package private) intwcwidth(java.lang.CharSequence str, int pos)(package private) intwcwidth(java.lang.CharSequence str, int start, int end, int pos)booleanyank()booleanyankPop()
-
-
-
Field Detail
-
JLINE_NOBELL
public static final java.lang.String JLINE_NOBELL
- See Also:
- Constant Field Values
-
JLINE_ESC_TIMEOUT
public static final java.lang.String JLINE_ESC_TIMEOUT
- See Also:
- Constant Field Values
-
JLINE_INPUTRC
public static final java.lang.String JLINE_INPUTRC
- See Also:
- Constant Field Values
-
INPUT_RC
public static final java.lang.String INPUT_RC
- See Also:
- Constant Field Values
-
DEFAULT_INPUT_RC
public static final java.lang.String DEFAULT_INPUT_RC
- See Also:
- Constant Field Values
-
JLINE_EXPAND_EVENTS
public static final java.lang.String JLINE_EXPAND_EVENTS
- See Also:
- Constant Field Values
-
BACKSPACE
public static final char BACKSPACE
- See Also:
- Constant Field Values
-
RESET_LINE
public static final char RESET_LINE
- See Also:
- Constant Field Values
-
KEYBOARD_BELL
public static final char KEYBOARD_BELL
- See Also:
- Constant Field Values
-
NULL_MASK
public static final char NULL_MASK
- See Also:
- Constant Field Values
-
TAB_WIDTH
public static final int TAB_WIDTH
- See Also:
- Constant Field Values
-
resources
private static final java.util.ResourceBundle resources
-
ESCAPE
private static final int ESCAPE
- See Also:
- Constant Field Values
-
READ_EXPIRED
private static final int READ_EXPIRED
- See Also:
- Constant Field Values
-
terminal
private final Terminal2 terminal
-
out
private final java.io.Writer out
-
buf
private final CursorBuffer buf
-
cursorOk
private boolean cursorOk
-
prompt
private java.lang.String prompt
-
promptLen
private int promptLen
-
expandEvents
private boolean expandEvents
-
bellEnabled
private boolean bellEnabled
-
handleUserInterrupt
private boolean handleUserInterrupt
-
handleLitteralNext
private boolean handleLitteralNext
-
mask
private java.lang.Character mask
-
echoCharacter
private java.lang.Character echoCharacter
-
originalBuffer
private CursorBuffer originalBuffer
-
searchTerm
private java.lang.StringBuffer searchTerm
-
previousSearchTerm
private java.lang.String previousSearchTerm
-
searchIndex
private int searchIndex
-
parenBlinkTimeout
private int parenBlinkTimeout
-
opBuffer
private final java.lang.StringBuilder opBuffer
-
pushBackChar
private final java.util.Stack<java.lang.Character> pushBackChar
-
in
private NonBlockingInputStream in
-
escapeTimeout
private long escapeTimeout
-
reader
private java.io.Reader reader
-
charSearchChar
private char charSearchChar
Last character searched for with a vi character search
-
charSearchLastInvokeChar
private char charSearchLastInvokeChar
-
charSearchFirstInvokeChar
private char charSearchFirstInvokeChar
-
yankBuffer
private java.lang.String yankBuffer
The vi yank buffer
-
killRing
private KillRing killRing
-
encoding
private java.lang.String encoding
-
quotedInsert
private boolean quotedInsert
-
recording
private boolean recording
-
macro
private java.lang.String macro
-
appName
private java.lang.String appName
-
inputrcUrl
private java.net.URL inputrcUrl
-
consoleKeys
private ConsoleKeys consoleKeys
-
commentBegin
private java.lang.String commentBegin
-
skipLF
private boolean skipLF
-
copyPasteDetection
private boolean copyPasteDetection
Set 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
private ConsoleReader.State state
-
JLINE_COMPLETION_THRESHOLD
public static final java.lang.String JLINE_COMPLETION_THRESHOLD
- See Also:
- Constant Field Values
-
completers
private final java.util.List<Completer> completers
-
completionHandler
private CompletionHandler completionHandler
-
autoprintThreshold
private int autoprintThreshold
The number of tab-completion candidates above which a warning will be prompted before showing all the candidates.
-
paginationEnabled
private boolean paginationEnabled
-
history
private History history
-
historyEnabled
private boolean historyEnabled
-
LINE_SEPARATOR
private static final java.lang.String LINE_SEPARATOR
-
maskThread
private java.lang.Thread maskThread
-
-
Constructor Detail
-
ConsoleReader
public ConsoleReader() throws java.io.IOException- Throws:
java.io.IOException
-
ConsoleReader
public ConsoleReader(java.io.InputStream in, java.io.OutputStream out) throws java.io.IOException- Throws:
java.io.IOException
-
ConsoleReader
public ConsoleReader(java.io.InputStream in, java.io.OutputStream out, Terminal term) throws java.io.IOException- Throws:
java.io.IOException
-
ConsoleReader
public ConsoleReader(@Nullable java.lang.String appName, java.io.InputStream in, java.io.OutputStream out, @Nullable Terminal term) throws java.io.IOException
- Throws:
java.io.IOException
-
-
Method Detail
-
setupSigCont
private void setupSigCont()
-
getInputRc
public static java.net.URL getInputRc() throws java.io.IOExceptionRetrieve the URL for the inputrc configuration file in effect. Intended use is for instantiating ConsoleKeys, to read inputrc variables.- Throws:
java.io.IOException
-
getKeys
public KeyMap getKeys()
-
setInput
void setInput(java.io.InputStream in) throws java.io.IOException- Throws:
java.io.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:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfacejava.io.Closeable
-
shutdown
@Deprecated public void shutdown()
Deprecated.Useclose()instead.Shuts the console reader down. The same asclose().
-
finalize
protected void finalize() throws java.lang.ThrowableShuts down the ConsoleReader if the JVM attempts to clean it up.- Overrides:
finalizein classjava.lang.Object- Throws:
java.lang.Throwable
-
getInput
public java.io.InputStream getInput()
-
getOutput
public java.io.Writer getOutput()
-
getTerminal
public Terminal getTerminal()
-
getCursorBuffer
public CursorBuffer 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 throwUserInterruptExceptionfromreadLine(). Otherwise, the JVM will handleSIGINTas 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
public void setCommentBegin(java.lang.String commentBegin)
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
public java.lang.String getCommentBegin()
- Returns:
- the string that will be used to start a comment when the insert-comment key is struck.
- Since:
- 2.7
-
setPrompt
public void setPrompt(java.lang.String prompt)
-
getPrompt
public java.lang.String getPrompt()
-
setEchoCharacter
public void setEchoCharacter(java.lang.Character c)
Set the echo character. For example, to have "*" entered when a password is typed:myConsoleReader.setEchoCharacter(new Character('*'));Setting the character tonullwill 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
public java.lang.Character getEchoCharacter()
Returns the echo character.
-
resetLine
protected final boolean resetLine() throws java.io.IOExceptionErase the current line.- Returns:
- false if we failed (e.g., the buffer was empty)
- Throws:
java.io.IOException
-
wcwidth
int wcwidth(java.lang.CharSequence str, int pos)
-
wcwidth
int wcwidth(java.lang.CharSequence str, int start, int end, int pos)
-
wcwidth
int wcwidth(int ucs, int pos)
-
nextTabStop
int nextTabStop(int pos)
-
getCursorPosition
int getCursorPosition()
-
lastLine
private static java.lang.String lastLine(java.lang.String str)
Returns the text after the last '\n'. prompt is returned if no '\n' characters are present. null is returned if prompt is null.
-
setCursorPosition
public boolean setCursorPosition(int position) throws java.io.IOExceptionMove the cursor position to the specified absolute index.- Throws:
java.io.IOException
-
setBuffer
private void setBuffer(java.lang.String buffer) throws java.io.IOExceptionSet 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:
java.io.IOException
-
setBuffer
private void setBuffer(java.lang.CharSequence buffer) throws java.io.IOException- Throws:
java.io.IOException
-
setBufferKeepPos
private void setBufferKeepPos(java.lang.String buffer) throws java.io.IOException- Throws:
java.io.IOException
-
setBufferKeepPos
private void setBufferKeepPos(java.lang.CharSequence buffer) throws java.io.IOException- Throws:
java.io.IOException
-
drawLine
public void drawLine() throws java.io.IOExceptionOutput put the prompt + the current buffer- Throws:
java.io.IOException
-
redrawLine
public void redrawLine() throws java.io.IOExceptionClear the line and redraw it.- Throws:
java.io.IOException
-
finishBuffer
final java.lang.String finishBuffer() throws java.io.IOExceptionClear the buffer and add its contents to the history.- Returns:
- the former contents of the buffer.
- Throws:
java.io.IOException
-
expandEvents
protected java.lang.String expandEvents(java.lang.String str) throws java.io.IOExceptionExpand event designator such as !!, !#, !3, etc... See http://www.gnu.org/software/bash/manual/html_node/Event-Designators.html- Throws:
java.io.IOException
-
putString
public void putString(java.lang.CharSequence str) throws java.io.IOExceptionWrite out the specified string to the buffer and the output stream.- Throws:
java.io.IOException
-
drawBuffer
private void drawBuffer(int clear) throws java.io.IOExceptionRedraw 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:
java.io.IOException
-
drawBuffer
private void drawBuffer() throws java.io.IOExceptionRedraw the rest of the buffer from the cursor onwards. This is necessary for inserting text into the buffer.- Throws:
java.io.IOException
-
clearAhead
private void clearAhead(int num, int pos) throws java.io.IOExceptionClear ahead the specified number of characters without moving the cursor.- Parameters:
num- the number of characters to clearpos- the current screen cursor position- Throws:
java.io.IOException
-
back
protected void back(int num) throws java.io.IOExceptionMove the visual cursor backward without modifying the buffer cursor.- Throws:
java.io.IOException
-
flush
public void flush() throws java.io.IOExceptionFlush 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:
java.io.IOException
-
backspaceAll
private int backspaceAll() throws java.io.IOException- Throws:
java.io.IOException
-
backspace
private int backspace(int num) throws java.io.IOExceptionIssue num backspaces.- Returns:
- the number of characters backed up
- Throws:
java.io.IOException
-
backspace
public boolean backspace() throws java.io.IOExceptionIssue a backspace.- Returns:
- true if successful
- Throws:
java.io.IOException
-
moveToEnd
protected boolean moveToEnd() throws java.io.IOException- Throws:
java.io.IOException
-
deleteCurrentCharacter
private boolean deleteCurrentCharacter() throws java.io.IOExceptionDelete the character at the current position and redraw the remainder of the buffer.- Throws:
java.io.IOException
-
viDeleteChangeYankToRemap
private Operation viDeleteChangeYankToRemap(Operation op)
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
private boolean viRubout(int count) throws java.io.IOExceptionDeletes the previous character from the cursor position- Parameters:
count- number of times to do it.- Returns:
- true if it was done.
- Throws:
java.io.IOException
-
viDelete
private boolean viDelete(int count) throws java.io.IOExceptionDeletes 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:
java.io.IOException
-
viChangeCase
private boolean viChangeCase(int count) throws java.io.IOExceptionSwitches 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:
java.io.IOException
-
viChangeChar
private boolean viChangeChar(int count, int c) throws java.io.IOExceptionImplements 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:
java.io.IOException
-
viPreviousWord
private boolean viPreviousWord(int count) throws java.io.IOExceptionThis 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:
java.io.IOException
-
viDeleteTo
private boolean viDeleteTo(int startPos, int endPos, boolean isChange) throws java.io.IOExceptionPerforms 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:
java.io.IOException
-
viYankTo
private boolean viYankTo(int startPos, int endPos) throws java.io.IOExceptionImplement 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:
java.io.IOException
-
viPut
private boolean viPut(int count) throws java.io.IOExceptionPasts 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:
java.io.IOException
-
viCharSearch
private boolean viCharSearch(int count, int invokeChar, int ch) throws java.io.IOExceptionSearches 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:
java.io.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
private boolean viNextWord(int count) throws java.io.IOExceptionThis 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:
java.io.IOException
-
viEndWord
private boolean viEndWord(int count) throws java.io.IOExceptionImplements 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:
java.io.IOException
-
previousWord
private boolean previousWord() throws java.io.IOException- Throws:
java.io.IOException
-
nextWord
private boolean nextWord() throws java.io.IOException- Throws:
java.io.IOException
-
unixWordRubout
private boolean unixWordRubout(int count) throws java.io.IOExceptionDeletes 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:
java.io.IOException
-
insertComment
private java.lang.String insertComment(boolean isViMode) throws java.io.IOException- Throws:
java.io.IOException
-
viSearch
private int viSearch(char searchChar) throws java.io.IOExceptionImplements vi search ("/" or "?").- Throws:
java.io.IOException
-
setParenBlinkTimeout
public void setParenBlinkTimeout(int timeout)
-
insertClose
private void insertClose(java.lang.String s) throws java.io.IOException- Throws:
java.io.IOException
-
viMatch
private boolean viMatch() throws java.io.IOExceptionImplements 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:
java.io.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
private boolean deletePreviousWord() throws java.io.IOException- Throws:
java.io.IOException
-
deleteNextWord
private boolean deleteNextWord() throws java.io.IOException- Throws:
java.io.IOException
-
capitalizeWord
private boolean capitalizeWord() throws java.io.IOException- Throws:
java.io.IOException
-
upCaseWord
private boolean upCaseWord() throws java.io.IOException- Throws:
java.io.IOException
-
downCaseWord
private boolean downCaseWord() throws java.io.IOException- Throws:
java.io.IOException
-
transposeChars
private boolean transposeChars(int count) throws java.io.IOExceptionPerforms 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:
java.io.IOException
-
isKeyMap
public boolean isKeyMap(java.lang.String name)
-
accept
public java.lang.String accept() throws java.io.IOExceptionThe equivalent of hitting <RET>. The line is considered complete and is returned.- Returns:
- The completed line of text.
- Throws:
java.io.IOException
-
abort
private void abort() throws java.io.IOException- Throws:
java.io.IOException
-
moveCursor
public int moveCursor(int num) throws java.io.IOExceptionMove 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:
java.io.IOException
-
moveInternal
private void moveInternal(int where) throws java.io.IOExceptionMove the cursor where characters, without checking the current buffer.- Parameters:
where- the number of characters to move to the right or left.- Throws:
java.io.IOException
-
moveCursorFromTo
private void moveCursorFromTo(int i0, int i1) throws java.io.IOException- Throws:
java.io.IOException
-
readCharacter
public int readCharacter() throws java.io.IOExceptionRead a character from the console.- Returns:
- the character, or -1 if an EOF is received.
- Throws:
java.io.IOException
-
readCharacter
public int readCharacter(boolean checkForAltKeyCombo) throws java.io.IOExceptionRead 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:
java.io.IOException
-
clearEcho
private int clearEcho(int c) throws java.io.IOExceptionClear the echoed characters for the specified character code.- Throws:
java.io.IOException
-
readCharacter
public int readCharacter(char... allowed) throws java.io.IOException- Throws:
java.io.IOException
-
readCharacter
public int readCharacter(boolean checkForAltKeyCombo, char... allowed) throws java.io.IOException- Throws:
java.io.IOException
-
readBinding
public java.lang.Object readBinding(KeyMap keys) throws java.io.IOException
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
nullif the end of stream has been reached - Throws:
java.io.IOException
-
getLastBinding
public java.lang.String getLastBinding()
-
readLine
public java.lang.String readLine() throws java.io.IOExceptionRead the next line and return the contents of the buffer.- Throws:
java.io.IOException
-
readLine
public java.lang.String readLine(java.lang.Character mask) throws java.io.IOExceptionRead the next line with the specified character mask. If null, then characters will be echoed. If 0, then no characters will be echoed.- Throws:
java.io.IOException
-
readLine
public java.lang.String readLine(java.lang.String prompt) throws java.io.IOException- Throws:
java.io.IOException
-
readLine
public java.lang.String readLine(java.lang.String prompt, java.lang.Character mask) throws java.io.IOExceptionRead 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:
java.io.IOException
-
setKeyMap
public boolean setKeyMap(java.lang.String name)
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
public java.lang.String 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
public java.lang.String readLine(java.lang.String prompt, java.lang.Character mask, java.lang.String buffer) throws java.io.IOExceptionRead 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:
java.io.IOException
-
readLineSimple
private java.lang.String readLineSimple() throws java.io.IOExceptionRead a line for unsupported terminals.- Throws:
java.io.IOException
-
addCompleter
public boolean addCompleter(Completer completer)
Add the specifiedCompleterto the list of handlers for tab-completion.- Parameters:
completer- theCompleterto add- Returns:
- true if it was successfully added
-
removeCompleter
public boolean removeCompleter(Completer completer)
Remove the specifiedCompleterfrom the list of handlers for tab-completion.- Parameters:
completer- TheCompleterto remove- Returns:
- True if it was successfully removed
-
getCompleters
public java.util.Collection<Completer> getCompleters()
Returns an unmodifiable list of all the completers.
-
setCompletionHandler
public void setCompletionHandler(CompletionHandler handler)
-
getCompletionHandler
public CompletionHandler getCompletionHandler()
-
complete
protected boolean complete() throws java.io.IOExceptionUse the completers to modify the buffer with the appropriate completions.- Returns:
- true if successful
- Throws:
java.io.IOException
-
printCompletionCandidates
protected void printCompletionCandidates() throws java.io.IOException- Throws:
java.io.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
public void setHistory(History history)
-
getHistory
public History 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
private boolean moveHistory(boolean next, int count) throws java.io.IOExceptionUsed 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:
java.io.IOException
-
moveHistory
private boolean moveHistory(boolean next) throws java.io.IOExceptionMove up or down the history tree.- Throws:
java.io.IOException
-
fmtPrint
private int fmtPrint(java.lang.CharSequence buff, int cursorPos) throws java.io.IOExceptionOutput the specified characters to the output stream without manipulating the current buffer.- Throws:
java.io.IOException
-
fmtPrint
private int fmtPrint(java.lang.CharSequence buff, int start, int end) throws java.io.IOException- Throws:
java.io.IOException
-
fmtPrint
private int fmtPrint(java.lang.CharSequence buff, int start, int end, int cursorPos) throws java.io.IOException- Throws:
java.io.IOException
-
print
public void print(java.lang.CharSequence s) throws java.io.IOExceptionOutput the specified string to the output stream (but not the buffer).- Throws:
java.io.IOException
-
println
public void println(java.lang.CharSequence s) throws java.io.IOException- Throws:
java.io.IOException
-
println
public void println() throws java.io.IOExceptionOutput a platform-dependant newline.- Throws:
java.io.IOException
-
rawPrint
final void rawPrint(int c) throws java.io.IOExceptionRaw output printing- Throws:
java.io.IOException
-
rawPrint
final void rawPrint(java.lang.String str) throws java.io.IOException- Throws:
java.io.IOException
-
rawPrint
private void rawPrint(char c, int num) throws java.io.IOException- Throws:
java.io.IOException
-
rawPrintln
private void rawPrintln(java.lang.String s) throws java.io.IOException- Throws:
java.io.IOException
-
delete
public boolean delete() throws java.io.IOExceptionIssue a delete.- Returns:
- true if successful
- Throws:
java.io.IOException
-
killLine
public boolean killLine() throws java.io.IOExceptionKill the buffer ahead of the current cursor position.- Returns:
- true if successful
- Throws:
java.io.IOException
-
yank
public boolean yank() throws java.io.IOException- Throws:
java.io.IOException
-
yankPop
public boolean yankPop() throws java.io.IOException- Throws:
java.io.IOException
-
clearScreen
public boolean clearScreen() throws java.io.IOExceptionClear the screen by issuing the ANSI "clear screen" code.- Throws:
java.io.IOException
-
beep
public void beep() throws java.io.IOExceptionIssue an audible keyboard bell.- Throws:
java.io.IOException
-
paste
public boolean paste() throws java.io.IOExceptionPaste the contents of the clipboard into the console buffer- Returns:
- true if clipboard contents pasted
- Throws:
java.io.IOException
-
addTriggeredAction
public 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 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
public void printColumns(java.util.Collection<? extends java.lang.CharSequence> items) throws java.io.IOExceptionOutput the specifiedCollectionin proper columns.- Throws:
java.io.IOException
-
beforeReadLine
private void beforeReadLine(java.lang.String prompt, java.lang.Character mask)
-
afterReadLine
private void afterReadLine()
-
resetPromptLine
public void resetPromptLine(java.lang.String prompt, java.lang.String buffer, int cursorDest) throws java.io.IOExceptionErases 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:
java.io.IOException
-
printSearchStatus
public void printSearchStatus(java.lang.String searchTerm, java.lang.String match) throws java.io.IOException- Throws:
java.io.IOException
-
printForwardSearchStatus
public void printForwardSearchStatus(java.lang.String searchTerm, java.lang.String match) throws java.io.IOException- Throws:
java.io.IOException
-
printSearchStatus
private void printSearchStatus(java.lang.String searchTerm, java.lang.String match, java.lang.String searchLabel) throws java.io.IOException- Throws:
java.io.IOException
-
restoreLine
public void restoreLine(java.lang.String originalPrompt, int cursorDest) throws java.io.IOException- Throws:
java.io.IOException
-
searchBackwards
public int searchBackwards(java.lang.String searchTerm, int startIndex)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
public int searchBackwards(java.lang.String searchTerm)
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
public int searchBackwards(java.lang.String searchTerm, int startIndex, boolean startsWith)
-
searchForwards
public int searchForwards(java.lang.String searchTerm, int startIndex)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
public int searchForwards(java.lang.String searchTerm)
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
public int searchForwards(java.lang.String searchTerm, int startIndex, boolean startsWith)
-
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
private boolean tputs(java.lang.String cap, java.lang.Object... params) throws java.io.IOException- Throws:
java.io.IOException
-
-