Interface LineReader
- All Known Implementing Classes:
LineReaderImpl
Thread safety
TheLineReader
implementations are not thread safe,
thus you should not attempt to use a single reader in several threads.
Any attempt to call one of the readLine
call while one is
already executing in a different thread will immediately result in an
IllegalStateException
being thrown. Other calls may lead to
unknown behaviors. There is one exception though: users are allowed to call
printAbove(String)
or printAbove(AttributedString)
at
any time to allow text to be printed above the current prompt.
Prompt strings
It is traditional for an interactive console-based program to print a short prompt string to signal that the user is expected to type a command. JLine supports 3 kinds of prompt string:- The normal prompt at the start (left) of the initial line of a command.
- An optional right prompt at the right border of the initial line.
- A start (left) prompt for continuation lines. I.e. the lines after the first line of a multi-line command.
All of these are specified with prompt templates,
which are similar to printf
format strings,
using the character '%'
to indicate special functionality.
%N
- A line number. This is the sum of
getLineNumber()
and a counter starting with 1 for the first continuation line. %M
- A short word explaining what is "missing". This is supplied from
the
EOFError.getMissing()
method, if provided. Defaults to an empty string. %
nP
c- Insert padding at this position, repeating the following character c as needed to bring the total prompt column width as specified by the digits n.
%P
c- As before, but use width from the initial prompt.
%%
- A literal
'%'
. %{
%}
- Text between a
%{
...%}
pair is printed as part of a prompt, but not interpreted by JLine (except that'%'
-escapes are processed). The text is assumed to take zero columns (not move the cursor). If it changes the style, you're responsible for changing it back. Standard ANSI escape sequences do not need to be within a%{
...%}
pair (though can be) since JLine knows how to deal with them. However, these delimiters are needed for unusual non-standard escape sequences.
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic enum
static enum
static enum
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final String
static final String
static final String
static final String
static final String
Timeout for ambiguous key sequences.static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
Completion style for displaying the liststatic final String
Completion style for displaying the candidate descriptionstatic final String
Completion style for displaying groups namestatic final String
static final String
static final String
static final String
static final String
static final String
Completion style for displaying the current selected itemstatic final String
Completion style for displaying the matching part of candidatesstatic final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
Number of matching errors that are accepted by the completion matcherstatic final String
static final String
static final String
static final String
static final String
static final String
static final String
Max buffer size for advanced features.static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
File system history path.static final String
Number of history items to keep in the history file.static final String
Colon separated list of patterns that will not be saved in history.static final String
static final String
static final String
static final String
static final String
static final String
static final String
Number of history items to keep in memory.static final String
New line automatic indentation after opening/closing bracket.static final String
static final String
Name of inputrc to read at line reader creation time.static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
When in multiline edit mode, this variable can be used to offset the line number displayed.static final String
static final String
static final String
tab completion: if candidates are more than list-max a question will be asked before displaying themstatic final String
static final String
static final String
Max number of times a command can be repeated.static final String
static final String
static final String
static final String
tab completion: if candidates are less than menu-list-max they are displayed in a list below the field to be completedstatic final String
static final String
static final String
static final String
Property for the "original" group namestatic final String
Property for the "others" group namestatic final String
static final String
static final String
System property that can be set to avoid a warning being logged when using a Parser which does not returnCompletingParsedLine
objects.static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
Set the template for prompts for secondary (continuation) lines.static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
Min buffer size for tab auto-suggestions.static final String
Prefix to automatically delegate variables to system propertiesstatic final String
Number of spaces to display a tabulation, the default is 4.static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
-
Method Summary
Modifier and TypeMethodDescriptionvoid
addCommandsInBuffer
(Collection<String> commands) Adds a collection of commands to the input buffer for execution.void
callWidget
(String name) Calls a widget by name.Returns the default key maps used by the LineReader.default void
editAndAddInBuffer
(File file) Opens a file in an external editor and adds its contents to the input buffer.void
editAndAddInBuffer
(Path file) Opens a file in an external editor and adds its contents to the input buffer.Returns the application name associated with this LineReader.Returns the current auto-suggestion type.Returns the current line buffer.Returns a map of all built-in widgets provided by the LineReader.Returns the expander associated with this LineReader.Returns the highlighter associated with this LineReader.Returns the history associated with this LineReader.Returns the name of the currently active key map.Returns all key maps registered with this LineReader.getKeys()
Returns the currently active key map.Returns the last key binding that was processed.Returns the parsed representation of the current line.Returns the parser associated with this LineReader.Returns the type of the currently active region selection.int
Returns the mark position of the currently active region.Returns the current search term when in history search mode.Returns the current tail tip text.Returns the terminal associated with this LineReader.getVariable
(String name) Returns the value of a variable.Returns a map of all variables set in the LineReader.Returns a map of all widgets registered with this LineReader.boolean
Check if a thread is currently in areadLine()
call.boolean
isSet
(LineReader.Option option) Checks if an option is set.option
(LineReader.Option option, boolean value) Sets an option in the LineReader and returns the LineReader for method chaining.void
printAbove
(String str) Prints a line above the prompt and redraw everything.void
Prints a string before the prompt and redraw everything.readLine()
Read the next line and return the contents of the buffer.Read the next line with the specified character mask.Read the next line with the specified prompt.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).Read a line from the inInputStream
, and return the line (without any trailing newlines).readLine
(String prompt, String rightPrompt, MaskingCallback maskingCallback, String buffer) Read a line from the inInputStream
, and return the line (without any trailing newlines).Read a mouse event when theInfoCmp.Capability.key_mouse
sequence has just been read on the input stream.void
Push back a key sequence that will be later consumed by the line reader.void
Sets the type of auto-suggestion to use.boolean
Sets the active key map by name.void
setOpt
(LineReader.Option option) Sets an option to true.void
setTailTip
(String tailTip) Sets the tail tip text.void
setVariable
(String name, Object value) Sets a variable in the LineReader.void
unsetOpt
(LineReader.Option option) Sets an option to false.Sets a variable in the LineReader and returns the LineReader for method chaining.void
zeroOut()
Clears any internal buffers and sensitive data.
-
Field Details
-
PROP_SUPPORT_PARSEDLINE
System property that can be set to avoid a warning being logged when using a Parser which does not returnCompletingParsedLine
objects.- See Also:
-
CALLBACK_INIT
- See Also:
-
CALLBACK_FINISH
- See Also:
-
CALLBACK_KEYMAP
- See Also:
-
ACCEPT_AND_INFER_NEXT_HISTORY
- See Also:
-
ACCEPT_AND_HOLD
- See Also:
-
ACCEPT_LINE
- See Also:
-
ACCEPT_LINE_AND_DOWN_HISTORY
- See Also:
-
ARGUMENT_BASE
- See Also:
-
BACKWARD_CHAR
- See Also:
-
BACKWARD_DELETE_CHAR
- See Also:
-
BACKWARD_DELETE_WORD
- See Also:
-
BACKWARD_KILL_LINE
- See Also:
-
BACKWARD_KILL_WORD
- See Also:
-
BACKWARD_WORD
- See Also:
-
BEEP
- See Also:
-
BEGINNING_OF_BUFFER_OR_HISTORY
- See Also:
-
BEGINNING_OF_HISTORY
- See Also:
-
BEGINNING_OF_LINE
- See Also:
-
BEGINNING_OF_LINE_HIST
- See Also:
-
CAPITALIZE_WORD
- See Also:
-
CHARACTER_SEARCH
- See Also:
-
CHARACTER_SEARCH_BACKWARD
- See Also:
-
CLEAR
- See Also:
-
CLEAR_SCREEN
- See Also:
-
COMPLETE_PREFIX
- See Also:
-
COMPLETE_WORD
- See Also:
-
COPY_PREV_WORD
- See Also:
-
COPY_REGION_AS_KILL
- See Also:
-
DELETE_CHAR
- See Also:
-
DELETE_CHAR_OR_LIST
- See Also:
-
DELETE_WORD
- See Also:
-
DIGIT_ARGUMENT
- See Also:
-
DO_LOWERCASE_VERSION
- See Also:
-
DOWN_CASE_WORD
- See Also:
-
DOWN_HISTORY
- See Also:
-
DOWN_LINE
- See Also:
-
DOWN_LINE_OR_HISTORY
- See Also:
-
DOWN_LINE_OR_SEARCH
- See Also:
-
EDIT_AND_EXECUTE_COMMAND
- See Also:
-
EMACS_BACKWARD_WORD
- See Also:
-
EMACS_EDITING_MODE
- See Also:
-
EMACS_FORWARD_WORD
- See Also:
-
END_OF_BUFFER_OR_HISTORY
- See Also:
-
END_OF_HISTORY
- See Also:
-
END_OF_LINE
- See Also:
-
END_OF_LINE_HIST
- See Also:
-
EXCHANGE_POINT_AND_MARK
- See Also:
-
EXECUTE_NAMED_CMD
- See Also:
-
EXPAND_HISTORY
- See Also:
-
EXPAND_OR_COMPLETE
- See Also:
-
EXPAND_OR_COMPLETE_PREFIX
- See Also:
-
EXPAND_WORD
- See Also:
-
FRESH_LINE
- See Also:
-
FORWARD_CHAR
- See Also:
-
FORWARD_WORD
- See Also:
-
HISTORY_BEGINNING_SEARCH_BACKWARD
- See Also:
-
HISTORY_BEGINNING_SEARCH_FORWARD
- See Also:
-
HISTORY_INCREMENTAL_PATTERN_SEARCH_BACKWARD
- See Also:
-
HISTORY_INCREMENTAL_PATTERN_SEARCH_FORWARD
- See Also:
-
HISTORY_INCREMENTAL_SEARCH_BACKWARD
- See Also:
-
HISTORY_INCREMENTAL_SEARCH_FORWARD
- See Also:
-
HISTORY_SEARCH_BACKWARD
- See Also:
-
HISTORY_SEARCH_FORWARD
- See Also:
-
INSERT_CLOSE_CURLY
- See Also:
-
INSERT_CLOSE_PAREN
- See Also:
-
INSERT_CLOSE_SQUARE
- See Also:
-
INFER_NEXT_HISTORY
- See Also:
-
INSERT_COMMENT
- See Also:
-
INSERT_LAST_WORD
- See Also:
-
KILL_BUFFER
- See Also:
-
KILL_LINE
- See Also:
-
KILL_REGION
- See Also:
-
KILL_WHOLE_LINE
- See Also:
-
KILL_WORD
- See Also:
-
LIST_CHOICES
- See Also:
-
LIST_EXPAND
- See Also:
-
MAGIC_SPACE
- See Also:
-
MENU_EXPAND_OR_COMPLETE
- See Also:
-
MENU_COMPLETE
- See Also:
-
MENU_SELECT
- See Also:
-
NEG_ARGUMENT
- See Also:
-
OVERWRITE_MODE
- See Also:
-
PUT_REPLACE_SELECTION
- See Also:
-
QUOTED_INSERT
- See Also:
-
READ_COMMAND
- See Also:
-
RECURSIVE_EDIT
- See Also:
-
REDISPLAY
- See Also:
-
REDRAW_LINE
- See Also:
-
REDO
- See Also:
-
REVERSE_MENU_COMPLETE
- See Also:
-
SELF_INSERT
- See Also:
-
SELF_INSERT_UNMETA
- See Also:
-
SEND_BREAK
- See Also:
-
SET_LOCAL_HISTORY
- See Also:
-
SET_MARK_COMMAND
- See Also:
-
SPELL_WORD
- See Also:
-
SPLIT_UNDO
- See Also:
-
TRANSPOSE_CHARS
- See Also:
-
TRANSPOSE_WORDS
- See Also:
-
UNDEFINED_KEY
- See Also:
-
UNDO
- See Also:
-
UNIVERSAL_ARGUMENT
- See Also:
-
UP_CASE_WORD
- See Also:
-
UP_HISTORY
- See Also:
-
UP_LINE
- See Also:
-
UP_LINE_OR_HISTORY
- See Also:
-
UP_LINE_OR_SEARCH
- See Also:
-
VI_ADD_EOL
- See Also:
-
VI_ADD_NEXT
- See Also:
-
VI_BACKWARD_BLANK_WORD
- See Also:
-
VI_BACKWARD_BLANK_WORD_END
- See Also:
-
VI_BACKWARD_CHAR
- See Also:
-
VI_BACKWARD_DELETE_CHAR
- See Also:
-
VI_BACKWARD_KILL_WORD
- See Also:
-
VI_BACKWARD_WORD
- See Also:
-
VI_BACKWARD_WORD_END
- See Also:
-
VI_BEGINNING_OF_LINE
- See Also:
-
VI_CHANGE
- See Also:
-
VI_CHANGE_EOL
- See Also:
-
VI_CHANGE_WHOLE_LINE
- See Also:
-
VI_CMD_MODE
- See Also:
-
VI_DELETE
- See Also:
-
VI_DELETE_CHAR
- See Also:
-
VI_DIGIT_OR_BEGINNING_OF_LINE
- See Also:
-
VI_DOWN_LINE_OR_HISTORY
- See Also:
-
VI_END_OF_LINE
- See Also:
-
VI_FETCH_HISTORY
- See Also:
-
VI_FIND_NEXT_CHAR
- See Also:
-
VI_FIND_NEXT_CHAR_SKIP
- See Also:
-
VI_FIND_PREV_CHAR
- See Also:
-
VI_FIND_PREV_CHAR_SKIP
- See Also:
-
VI_FIRST_NON_BLANK
- See Also:
-
VI_FORWARD_BLANK_WORD
- See Also:
-
VI_FORWARD_BLANK_WORD_END
- See Also:
-
VI_FORWARD_CHAR
- See Also:
-
VI_FORWARD_WORD
- See Also:
-
VI_FORWARD_WORD_END
- See Also:
-
VI_GOTO_COLUMN
- See Also:
-
VI_HISTORY_SEARCH_BACKWARD
- See Also:
-
VI_HISTORY_SEARCH_FORWARD
- See Also:
-
VI_INSERT
- See Also:
-
VI_INSERT_BOL
- See Also:
-
VI_INSERT_COMMENT
- See Also:
-
VI_JOIN
- See Also:
-
VI_KILL_EOL
- See Also:
-
VI_KILL_LINE
- See Also:
-
VI_MATCH_BRACKET
- See Also:
-
VI_OPEN_LINE_ABOVE
- See Also:
-
VI_OPEN_LINE_BELOW
- See Also:
-
VI_OPER_SWAP_CASE
- See Also:
-
VI_PUT_AFTER
- See Also:
-
VI_PUT_BEFORE
- See Also:
-
VI_QUOTED_INSERT
- See Also:
-
VI_REPEAT_CHANGE
- See Also:
-
VI_REPEAT_FIND
- See Also:
-
VI_REPEAT_SEARCH
- See Also:
-
VI_REPLACE
- See Also:
-
VI_REPLACE_CHARS
- See Also:
-
VI_REV_REPEAT_FIND
- See Also:
-
VI_REV_REPEAT_SEARCH
- See Also:
-
VI_SET_BUFFER
- See Also:
-
VI_SUBSTITUTE
- See Also:
-
VI_SWAP_CASE
- See Also:
-
VI_UNDO_CHANGE
- See Also:
-
VI_UP_LINE_OR_HISTORY
- See Also:
-
VI_YANK
- See Also:
-
VI_YANK_EOL
- See Also:
-
VI_YANK_WHOLE_LINE
- See Also:
-
VISUAL_LINE_MODE
- See Also:
-
VISUAL_MODE
- See Also:
-
WHAT_CURSOR_POSITION
- See Also:
-
YANK
- See Also:
-
YANK_POP
- See Also:
-
MOUSE
- See Also:
-
FOCUS_IN
- See Also:
-
FOCUS_OUT
- See Also:
-
BEGIN_PASTE
- See Also:
-
VICMD
- See Also:
-
VIINS
- See Also:
-
VIOPP
- See Also:
-
VISUAL
- See Also:
-
MAIN
- See Also:
-
EMACS
- See Also:
-
SAFE
- See Also:
-
DUMB
- See Also:
-
MENU
- See Also:
-
BIND_TTY_SPECIAL_CHARS
- See Also:
-
COMMENT_BEGIN
- See Also:
-
BELL_STYLE
- See Also:
-
PREFER_VISIBLE_BELL
- See Also:
-
LIST_MAX
tab completion: if candidates are more than list-max a question will be asked before displaying them- See Also:
-
MENU_LIST_MAX
tab completion: if candidates are less than menu-list-max they are displayed in a list below the field to be completed- See Also:
-
DISABLE_HISTORY
- See Also:
-
DISABLE_COMPLETION
- See Also:
-
EDITING_MODE
- See Also:
-
KEYMAP
- See Also:
-
BLINK_MATCHING_PAREN
- See Also:
-
WORDCHARS
- See Also:
-
REMOVE_SUFFIX_CHARS
- See Also:
-
SEARCH_TERMINATORS
- See Also:
-
ERRORS
Number of matching errors that are accepted by the completion matcher- See Also:
-
OTHERS_GROUP_NAME
Property for the "others" group name- See Also:
-
ORIGINAL_GROUP_NAME
Property for the "original" group name- See Also:
-
COMPLETION_STYLE_GROUP
Completion style for displaying groups name- See Also:
-
COMPLETION_STYLE_LIST_GROUP
- See Also:
-
COMPLETION_STYLE_SELECTION
Completion style for displaying the current selected item- See Also:
-
COMPLETION_STYLE_LIST_SELECTION
- See Also:
-
COMPLETION_STYLE_DESCRIPTION
Completion style for displaying the candidate description- See Also:
-
COMPLETION_STYLE_LIST_DESCRIPTION
- See Also:
-
COMPLETION_STYLE_STARTING
Completion style for displaying the matching part of candidates- See Also:
-
COMPLETION_STYLE_LIST_STARTING
- See Also:
-
COMPLETION_STYLE_BACKGROUND
Completion style for displaying the list- See Also:
-
COMPLETION_STYLE_LIST_BACKGROUND
- See Also:
-
SECONDARY_PROMPT_PATTERN
Set the template for prompts for secondary (continuation) lines. This is a prompt template as described in the class header.- See Also:
-
LINE_OFFSET
When in multiline edit mode, this variable can be used to offset the line number displayed.- See Also:
-
AMBIGUOUS_BINDING
Timeout for ambiguous key sequences. If the key sequence is ambiguous, i.e. there is a matching sequence but the sequence is also a prefix for other bindings, the next key press will be waited for a specified amount of time. If the timeout elapses, the matched sequence will be used.- See Also:
-
HISTORY_IGNORE
Colon separated list of patterns that will not be saved in history.- See Also:
-
HISTORY_FILE
File system history path.- See Also:
-
HISTORY_SIZE
Number of history items to keep in memory.- See Also:
-
HISTORY_FILE_SIZE
Number of history items to keep in the history file.- See Also:
-
INDENTATION
New line automatic indentation after opening/closing bracket.- See Also:
-
FEATURES_MAX_BUFFER_SIZE
Max buffer size for advanced features. Once the length of the buffer reaches this threshold, no advanced features will be enabled. This includes the undo buffer, syntax highlighting, parsing, etc....- See Also:
-
SUGGESTIONS_MIN_BUFFER_SIZE
Min buffer size for tab auto-suggestions. For shorter buffer sizes auto-suggestions are not resolved.- See Also:
-
MAX_REPEAT_COUNT
Max number of times a command can be repeated.- See Also:
-
TAB_WIDTH
Number of spaces to display a tabulation, the default is 4.- See Also:
-
INPUT_RC_FILE_NAME
Name of inputrc to read at line reader creation time.- See Also:
-
SYSTEM_PROPERTY_PREFIX
Prefix to automatically delegate variables to system properties- See Also:
-
-
Method Details
-
defaultKeyMaps
Returns the default key maps used by the LineReader.These key maps define the standard key bindings for different editing modes such as Emacs mode, Vi command mode, Vi insert mode, etc.
- Returns:
- a map of key map names to key maps
-
readLine
Read the next line and return the contents of the buffer. Equivalent toreadLine(null, null, null)
.- Returns:
- the line read
- Throws:
UserInterruptException
- if readLine was interrupted (using Ctrl-C for example)EndOfFileException
- if an EOF has been found (using Ctrl-D for example)IOError
- in case of other i/o errors
-
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. Equivalent toreadLine(null, mask, null)
- Parameters:
mask
- The mask character,null
or0
.- Returns:
- A line that is read from the terminal, can never be null.
- Throws:
UserInterruptException
- if readLine was interrupted (using Ctrl-C for example)EndOfFileException
- if an EOF has been found (using Ctrl-D for example)IOError
- in case of other i/o errors
-
readLine
Read the next line with the specified prompt. If null, then the default prompt will be used. Equivalent toreadLine(prompt, null, null)
- Parameters:
prompt
- The prompt to issue to the terminal, may be null.- Returns:
- A line that is read from the terminal, can never be null.
- Throws:
UserInterruptException
- if readLine was interrupted (using Ctrl-C for example)EndOfFileException
- if an EOF has been found (using Ctrl-D for example)IOError
- in case of other i/o errors
-
readLine
Read a line from the inInputStream
, and return the line (without any trailing newlines). Equivalent toreadLine(prompt, mask, null)
- Parameters:
prompt
- The prompt to issue to the terminal, may be null.mask
- The mask character,null
or0
.- Returns:
- A line that is read from the terminal, can never be null.
- Throws:
UserInterruptException
- if readLine was interrupted (using Ctrl-C for example)EndOfFileException
- if an EOF has been found (using Ctrl-D for example)IOError
- in case of other i/o errors
-
readLine
String readLine(String prompt, Character mask, String buffer) throws UserInterruptException, EndOfFileException Read a line from the inInputStream
, and return the line (without any trailing newlines). Equivalent toreadLine(prompt, null, mask, buffer)
- Parameters:
prompt
- The prompt to issue to the terminal, may be null. This is a template, with optional'%'
escapes, as described in the class header.mask
- The character mask, may be null.buffer
- The default value presented to the user to edit, may be null.- Returns:
- A line that is read from the terminal, can never be null.
- Throws:
UserInterruptException
- if readLine was interrupted (using Ctrl-C for example)EndOfFileException
- if an EOF has been found (using Ctrl-D for example)IOError
- in case of other i/o errors
-
readLine
String readLine(String prompt, String rightPrompt, Character mask, String buffer) throws UserInterruptException, EndOfFileException Read a line from the inInputStream
, and return the line (without any trailing newlines).- Parameters:
prompt
- The prompt to issue to the terminal, may be null. This is a template, with optional'%'
escapes, as described in the class header.rightPrompt
- The right prompt This is a template, with optional'%'
escapes, as described in the class header.mask
- The character mask, may be null.buffer
- The default value presented to the user to edit, may be null.- Returns:
- A line that is read from the terminal, can never be null.
- Throws:
UserInterruptException
- if readLine was interrupted (using Ctrl-C for example)EndOfFileException
- if an EOF has been found (using Ctrl-D for example)IOError
- in case of other i/o errors
-
readLine
String readLine(String prompt, String rightPrompt, MaskingCallback maskingCallback, String buffer) throws UserInterruptException, EndOfFileException Read a line from the inInputStream
, and return the line (without any trailing newlines).- Parameters:
prompt
- The prompt to issue to the terminal, may be null. This is a template, with optional'%'
escapes, as described in the class header.rightPrompt
- The right prompt This is a template, with optional'%'
escapes, as described in the class header.maskingCallback
- TheMaskingCallback
to use when displaying lines and adding them to the lineHistory
buffer
- The default value presented to the user to edit, may be null.- Returns:
- A line that is read from the terminal, can never be null.
- Throws:
UserInterruptException
- if readLine was interrupted (using Ctrl-C for example)EndOfFileException
- if an EOF has been found (using Ctrl-D for example)IOError
- in case of other i/o errors
-
printAbove
Prints a line above the prompt and redraw everything. If the LineReader is not actually reading a line, the string will simply be printed to the terminal.- Parameters:
str
- the string to print- See Also:
-
printAbove
Prints a string before the prompt and redraw everything. If the LineReader is not actually reading a line, the string will simply be printed to the terminal.- Parameters:
str
- the string to print- See Also:
-
isReading
boolean isReading()Check if a thread is currently in areadLine()
call.- Returns:
true
if there is an ongoingreadLine()
call.
-
variable
Sets a variable in the LineReader and returns the LineReader for method chaining.Variables control various aspects of the LineReader's behavior. See the various variable constants defined in this interface for available options.
- Parameters:
name
- the variable namevalue
- the variable value- Returns:
- this LineReader
-
option
Sets an option in the LineReader and returns the LineReader for method chaining.Options control various aspects of the LineReader's behavior. See the
LineReader.Option
enum for available options.- Parameters:
option
- the option to setvalue
- the option value- Returns:
- this LineReader
-
callWidget
Calls a widget by name.Widgets are functions that perform editing operations. This method allows invoking a widget programmatically rather than through a key binding.
- Parameters:
name
- the name of the widget to call
-
getVariables
Returns a map of all variables set in the LineReader.Variables control various aspects of the LineReader's behavior. See the various variable constants defined in this interface for available options.
- Returns:
- a map of variable names to their values
-
getVariable
Returns the value of a variable.Variables control various aspects of the LineReader's behavior. See the various variable constants defined in this interface for available options.
- Parameters:
name
- the variable name- Returns:
- the variable value, or null if the variable is not set
-
setVariable
Sets a variable in the LineReader.Variables control various aspects of the LineReader's behavior. See the various variable constants defined in this interface for available options.
- Parameters:
name
- the variable namevalue
- the variable value
-
isSet
Checks if an option is set.Options control various aspects of the LineReader's behavior. See the
LineReader.Option
enum for available options.- Parameters:
option
- the option to check- Returns:
- true if the option is set, false otherwise
-
setOpt
Sets an option to true.Options control various aspects of the LineReader's behavior. See the
LineReader.Option
enum for available options.- Parameters:
option
- the option to set
-
unsetOpt
Sets an option to false.Options control various aspects of the LineReader's behavior. See the
LineReader.Option
enum for available options.- Parameters:
option
- the option to unset
-
getTerminal
Terminal getTerminal()Returns the terminal associated with this LineReader.The terminal is used for input/output operations and provides information about the terminal capabilities and size.
- Returns:
- the terminal
-
getWidgets
Returns a map of all widgets registered with this LineReader.Widgets are functions that perform editing operations and can be bound to key sequences.
- Returns:
- a map of widget names to widgets
-
getBuiltinWidgets
Returns a map of all built-in widgets provided by the LineReader.Built-in widgets implement standard editing operations like cursor movement, text deletion, history navigation, etc.
- Returns:
- a map of built-in widget names to widgets
-
getBuffer
Buffer getBuffer()Returns the current line buffer.The buffer contains the text that the user is currently editing. It provides methods for manipulating the text and cursor position.
- Returns:
- the current line buffer
-
getAppName
String getAppName()Returns the application name associated with this LineReader.The application name is used for various purposes, such as naming history files and identifying the application in terminal titles.
- Returns:
- the application name
-
runMacro
Push back a key sequence that will be later consumed by the line reader. This method can be used after reading the cursor position usingTerminal.getCursorPosition(IntConsumer)
.- Parameters:
macro
- the key sequence to push back- See Also:
-
readMouseEvent
MouseEvent readMouseEvent()Read a mouse event when theInfoCmp.Capability.key_mouse
sequence has just been read on the input stream. Compared toTerminal.readMouseEvent()
, this method takes into account keys that have been pushed back usingrunMacro(String)
.- Returns:
- the mouse event
- See Also:
-
getHistory
History getHistory()Returns the history associated with this LineReader.The history stores previously entered command lines and provides methods for navigating, searching, and managing history entries.
- Returns:
- the command history
-
getParser
Parser getParser()Returns the parser associated with this LineReader.The parser is responsible for breaking command lines into tokens according to the syntax rules of the shell or application.
- Returns:
- the parser
-
getHighlighter
Highlighter getHighlighter()Returns the highlighter associated with this LineReader.The highlighter is responsible for applying syntax highlighting to the command line as the user types.
- Returns:
- the highlighter
-
getExpander
Expander getExpander()Returns the expander associated with this LineReader.The expander is responsible for expanding special syntax in the command line, such as history references (e.g., !!, !$) and variables (e.g., $HOME).
- Returns:
- the expander
-
getKeyMaps
Returns all key maps registered with this LineReader.Key maps define the mappings from key sequences to actions for different editing modes (e.g., Emacs mode, Vi command mode, Vi insert mode).
- Returns:
- a map of key map names to key maps
-
getKeyMap
String getKeyMap()Returns the name of the currently active key map.The active key map determines how key presses are interpreted and which actions they trigger.
- Returns:
- the name of the active key map
-
setKeyMap
Sets the active key map by name.The active key map determines how key presses are interpreted and which actions they trigger.
- Parameters:
name
- the name of the key map to activate- Returns:
- true if the key map was successfully set, false if the key map does not exist
-
getKeys
Returns the currently active key map.The active key map determines how key presses are interpreted and which actions they trigger.
- Returns:
- the active key map
-
getParsedLine
ParsedLine getParsedLine()Returns the parsed representation of the current line.The parsed line contains the tokenized form of the current input line, broken down according to the syntax rules of the parser.
- Returns:
- the parsed line, or null if the line has not been parsed yet
-
getSearchTerm
String getSearchTerm()Returns the current search term when in history search mode.This is the string that the user is searching for in the command history.
- Returns:
- the current search term, or null if not in search mode
-
getRegionActive
LineReader.RegionType getRegionActive()Returns the type of the currently active region selection.The region is a selected portion of text in the buffer, similar to a selection in a text editor.
- Returns:
- the type of the active region, or
LineReader.RegionType.NONE
if no region is active
-
getRegionMark
int getRegionMark()Returns the mark position of the currently active region.The mark is one endpoint of the selected region, with the cursor being the other endpoint.
- Returns:
- the position of the mark, or -1 if no region is active
-
addCommandsInBuffer
Adds a collection of commands to the input buffer for execution.These commands will be executed one by one when the user accepts the current line. This is useful for implementing features like command scripts or macros.
- Parameters:
commands
- the commands to add to the buffer
-
editAndAddInBuffer
Opens a file in an external editor and adds its contents to the input buffer.This method allows the user to edit a file in their preferred text editor and then have its contents added to the input buffer for execution.
- Parameters:
file
- the file to edit, or null to create a temporary file- Throws:
Exception
- if an error occurs while editing the file- See Also:
-
editAndAddInBuffer
Opens a file in an external editor and adds its contents to the input buffer.This method allows the user to edit a file in their preferred text editor and then have its contents added to the input buffer for execution.
- Parameters:
file
- the file to edit, or null to create a temporary file- Throws:
Exception
- if an error occurs while editing the file
-
getLastBinding
String getLastBinding()Returns the last key binding that was processed.This is the string representation of the last key sequence that triggered an action.
- Returns:
- the last key binding, or null if no binding has been processed
-
getTailTip
String getTailTip()Returns the current tail tip text.The tail tip is a hint or suggestion displayed at the end of the current line, typically showing command syntax or parameter information.
- Returns:
- the current tail tip text, or null if no tail tip is set
-
setTailTip
Sets the tail tip text.The tail tip is a hint or suggestion displayed at the end of the current line, typically showing command syntax or parameter information.
- Parameters:
tailTip
- the tail tip text to display, or null to clear the tail tip
-
setAutosuggestion
Sets the type of auto-suggestion to use.Auto-suggestions provide inline completion suggestions as the user types, based on history, completers, or other sources.
- Parameters:
type
- the type of auto-suggestion to use
-
getAutosuggestion
LineReader.SuggestionType getAutosuggestion()Returns the current auto-suggestion type.Auto-suggestions provide inline completion suggestions as the user types, based on history, completers, or other sources.
- Returns:
- the current auto-suggestion type
-
zeroOut
void zeroOut()Clears any internal buffers and sensitive data.This method is used to ensure that sensitive information, such as passwords or other confidential data, is removed from memory when it's no longer needed. It should be called when the LineReader is no longer in use or before reading sensitive information.
-