Class LineReaderImpl

java.lang.Object
org.jline.reader.impl.LineReaderImpl
All Implemented Interfaces:
Flushable, LineReader

public class LineReaderImpl extends Object implements LineReader, Flushable
The default implementation of the LineReader interface.

This class provides a comprehensive implementation of line editing capabilities for interactive terminal applications, including:

  • Command history navigation and management
  • Tab completion with customizable completion strategies
  • Syntax highlighting
  • Emacs and Vi editing modes
  • Key binding customization
  • Cut and paste with kill ring
  • Undo/redo functionality
  • Search through history
  • Multi-line editing
  • Character masking for password input

This implementation is highly configurable through options and variables that control various aspects of its behavior. It also provides a rich set of widgets (editing functions) that can be bound to key sequences.

Most applications should not create instances of this class directly, but instead use the LineReaderBuilder to create properly configured instances.

See Also:
  • Field Details

  • Constructor Details

  • Method Details

    • getTerminal

      public Terminal getTerminal()
      Description copied from interface: LineReader
      Returns the terminal associated with this LineReader.

      The terminal is used for input/output operations and provides information about the terminal capabilities and size.

      Specified by:
      getTerminal in interface LineReader
      Returns:
      the terminal
    • getAppName

      public String getAppName()
      Description copied from interface: LineReader
      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.

      Specified by:
      getAppName in interface LineReader
      Returns:
      the application name
    • getKeyMaps

      public Map<String,KeyMap<Binding>> getKeyMaps()
      Description copied from interface: LineReader
      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).

      Specified by:
      getKeyMaps in interface LineReader
      Returns:
      a map of key map names to key maps
    • getKeys

      public KeyMap<Binding> getKeys()
      Description copied from interface: LineReader
      Returns the currently active key map.

      The active key map determines how key presses are interpreted and which actions they trigger.

      Specified by:
      getKeys in interface LineReader
      Returns:
      the active key map
    • getWidgets

      public Map<String,Widget> getWidgets()
      Description copied from interface: LineReader
      Returns a map of all widgets registered with this LineReader.

      Widgets are functions that perform editing operations and can be bound to key sequences.

      Specified by:
      getWidgets in interface LineReader
      Returns:
      a map of widget names to widgets
    • getBuiltinWidgets

      public Map<String,Widget> getBuiltinWidgets()
      Description copied from interface: LineReader
      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.

      Specified by:
      getBuiltinWidgets in interface LineReader
      Returns:
      a map of built-in widget names to widgets
    • getBuffer

      public Buffer getBuffer()
      Description copied from interface: LineReader
      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.

      Specified by:
      getBuffer in interface LineReader
      Returns:
      the current line buffer
    • setAutosuggestion

      public void setAutosuggestion(LineReader.SuggestionType type)
      Description copied from interface: LineReader
      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.

      Specified by:
      setAutosuggestion in interface LineReader
      Parameters:
      type - the type of auto-suggestion to use
    • getAutosuggestion

      public LineReader.SuggestionType getAutosuggestion()
      Description copied from interface: LineReader
      Returns the current auto-suggestion type.

      Auto-suggestions provide inline completion suggestions as the user types, based on history, completers, or other sources.

      Specified by:
      getAutosuggestion in interface LineReader
      Returns:
      the current auto-suggestion type
    • getTailTip

      public String getTailTip()
      Description copied from interface: LineReader
      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.

      Specified by:
      getTailTip in interface LineReader
      Returns:
      the current tail tip text, or null if no tail tip is set
    • setTailTip

      public void setTailTip(String tailTip)
      Description copied from interface: LineReader
      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.

      Specified by:
      setTailTip in interface LineReader
      Parameters:
      tailTip - the tail tip text to display, or null to clear the tail tip
    • runMacro

      public void runMacro(String macro)
      Description copied from interface: LineReader
      Push back a key sequence that will be later consumed by the line reader. This method can be used after reading the cursor position using Terminal.getCursorPosition(IntConsumer).
      Specified by:
      runMacro in interface LineReader
      Parameters:
      macro - the key sequence to push back
      See Also:
    • readMouseEvent

      public MouseEvent readMouseEvent()
      Description copied from interface: LineReader
      Read a mouse event when the InfoCmp.Capability.key_mouse sequence has just been read on the input stream. Compared to Terminal.readMouseEvent(), this method takes into account keys that have been pushed back using LineReader.runMacro(String).
      Specified by:
      readMouseEvent in interface LineReader
      Returns:
      the mouse event
      See Also:
    • setCompleter

      public void setCompleter(Completer completer)
      Set the completer.
      Parameters:
      completer - the completer to use
    • getCompleter

      public Completer getCompleter()
      Returns the completer.
      Returns:
      the completer
    • setHistory

      public void setHistory(History history)
    • getHistory

      public History getHistory()
      Description copied from interface: LineReader
      Returns the history associated with this LineReader.

      The history stores previously entered command lines and provides methods for navigating, searching, and managing history entries.

      Specified by:
      getHistory in interface LineReader
      Returns:
      the command history
    • setHighlighter

      public void setHighlighter(Highlighter highlighter)
    • getHighlighter

      public Highlighter getHighlighter()
      Description copied from interface: LineReader
      Returns the highlighter associated with this LineReader.

      The highlighter is responsible for applying syntax highlighting to the command line as the user types.

      Specified by:
      getHighlighter in interface LineReader
      Returns:
      the highlighter
    • getParser

      public Parser getParser()
      Description copied from interface: LineReader
      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.

      Specified by:
      getParser in interface LineReader
      Returns:
      the parser
    • setParser

      public void setParser(Parser parser)
    • getExpander

      public Expander getExpander()
      Description copied from interface: LineReader
      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).

      Specified by:
      getExpander in interface LineReader
      Returns:
      the expander
    • setExpander

      public void setExpander(Expander expander)
    • setCompletionMatcher

      public void setCompletionMatcher(CompletionMatcher completionMatcher)
    • readLine

      Read the next line and return the contents of the buffer.
      Specified by:
      readLine in interface LineReader
      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)
    • 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.
      Specified by:
      readLine in interface LineReader
      Parameters:
      mask - The mask character, null or 0.
      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)
    • readLine

      public String readLine(String prompt) throws UserInterruptException, EndOfFileException
      Read a line from the in InputStream, and return the line (without any trailing newlines).
      Specified by:
      readLine in interface LineReader
      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)
    • readLine

      public String readLine(String prompt, Character mask) throws UserInterruptException, EndOfFileException
      Read a line from the in InputStream, and return the line (without any trailing newlines).
      Specified by:
      readLine in interface LineReader
      Parameters:
      prompt - The prompt to issue to the terminal, may be null.
      mask - The mask character, null or 0.
      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)
    • readLine

      public String readLine(String prompt, Character mask, String buffer) throws UserInterruptException, EndOfFileException
      Read a line from the in InputStream, and return the line (without any trailing newlines).
      Specified by:
      readLine in interface LineReader
      Parameters:
      prompt - The prompt to issue to the terminal, may be null.
      mask - The mask character, null or 0.
      buffer - A string that will be set for editing.
      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)
    • readLine

      public String readLine(String prompt, String rightPrompt, Character mask, String buffer) throws UserInterruptException, EndOfFileException
      Read a line from the in InputStream, and return the line (without any trailing newlines).
      Specified by:
      readLine in interface LineReader
      Parameters:
      prompt - The prompt to issue to the terminal, may be null.
      rightPrompt - The prompt to issue to the right of the terminal, may be null.
      mask - The mask character, null or 0.
      buffer - A string that will be set for editing.
      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)
    • readLine

      public String readLine(String prompt, String rightPrompt, MaskingCallback maskingCallback, String buffer) throws UserInterruptException, EndOfFileException
      Read a line from the in InputStream, and return the line (without any trailing newlines).
      Specified by:
      readLine in interface LineReader
      Parameters:
      prompt - The prompt to issue to the terminal, may be null.
      rightPrompt - The prompt to issue to the right of the terminal, may be null.
      maskingCallback - The callback used to mask parts of the edited line.
      buffer - A string that will be set for editing.
      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)
    • printAbove

      public void printAbove(String str)
      Description copied from interface: LineReader
      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.
      Specified by:
      printAbove in interface LineReader
      Parameters:
      str - the string to print
      See Also:
    • printAbove

      public void printAbove(AttributedString str)
      Description copied from interface: LineReader
      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.
      Specified by:
      printAbove in interface LineReader
      Parameters:
      str - the string to print
      See Also:
    • isReading

      public boolean isReading()
      Description copied from interface: LineReader
      Check if a thread is currently in a readLine() call.
      Specified by:
      isReading in interface LineReader
      Returns:
      true if there is an ongoing readLine() call.
    • freshLine

      protected boolean freshLine()
    • callWidget

      public void callWidget(String name)
      Description copied from interface: LineReader
      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.

      Specified by:
      callWidget in interface LineReader
      Parameters:
      name - the name of the widget to call
    • redrawLine

      public boolean redrawLine()
      Clear the line and redraw it.
      Returns:
      true
    • putString

      public void putString(CharSequence str)
      Write out the specified string to the buffer and the output stream.
      Parameters:
      str - the char sequence to write in the buffer
    • flush

      public void flush()
      Flush the terminal output stream. This is important for printout out single characters (like a buf.backspace or keyboard) that we want the terminal to handle immediately.
      Specified by:
      flush in interface Flushable
    • isKeyMap

      public boolean isKeyMap(String name)
    • readCharacter

      public int readCharacter()
      Read a character from the terminal.
      Returns:
      the character, or -1 if an EOF is received.
    • peekCharacter

      public int peekCharacter(long timeout)
    • doReadBinding

      protected <T> T doReadBinding(KeyMap<T> keys, KeyMap<T> local)
    • doReadStringUntil

      protected String doReadStringUntil(String sequence)
    • readBinding

      public Binding readBinding(KeyMap<Binding> keys)
      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
    • readBinding

      public Binding readBinding(KeyMap<Binding> keys, KeyMap<Binding> local)
    • getParsedLine

      public ParsedLine getParsedLine()
      Description copied from interface: LineReader
      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.

      Specified by:
      getParsedLine in interface LineReader
      Returns:
      the parsed line, or null if the line has not been parsed yet
    • getLastBinding

      public String getLastBinding()
      Description copied from interface: LineReader
      Returns the last key binding that was processed.

      This is the string representation of the last key sequence that triggered an action.

      Specified by:
      getLastBinding in interface LineReader
      Returns:
      the last key binding, or null if no binding has been processed
    • getSearchTerm

      public String getSearchTerm()
      Description copied from interface: LineReader
      Returns the current search term when in history search mode.

      This is the string that the user is searching for in the command history.

      Specified by:
      getSearchTerm in interface LineReader
      Returns:
      the current search term, or null if not in search mode
    • getRegionActive

      public LineReader.RegionType getRegionActive()
      Description copied from interface: LineReader
      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.

      Specified by:
      getRegionActive in interface LineReader
      Returns:
      the type of the active region, or LineReader.RegionType.NONE if no region is active
    • getRegionMark

      public int getRegionMark()
      Description copied from interface: LineReader
      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.

      Specified by:
      getRegionMark in interface LineReader
      Returns:
      the position of the mark, or -1 if no region is active
    • setKeyMap

      public boolean setKeyMap(String name)
      Sets the current keymap by name. Supported keymaps are "emacs", "viins", "vicmd".
      Specified by:
      setKeyMap in interface LineReader
      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 String getKeyMap()
      Returns the name of the current key mapping.
      Specified by:
      getKeyMap in interface LineReader
      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).
    • variable

      public LineReader variable(String name, Object value)
      Description copied from interface: LineReader
      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.

      Specified by:
      variable in interface LineReader
      Parameters:
      name - the variable name
      value - the variable value
      Returns:
      this LineReader
    • getVariables

      public Map<String,Object> getVariables()
      Description copied from interface: LineReader
      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.

      Specified by:
      getVariables in interface LineReader
      Returns:
      a map of variable names to their values
    • getVariable

      public Object getVariable(String name)
      Description copied from interface: LineReader
      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.

      Specified by:
      getVariable in interface LineReader
      Parameters:
      name - the variable name
      Returns:
      the variable value, or null if the variable is not set
    • setVariable

      public void setVariable(String name, Object value)
      Description copied from interface: LineReader
      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.

      Specified by:
      setVariable in interface LineReader
      Parameters:
      name - the variable name
      value - the variable value
    • option

      public LineReader option(LineReader.Option option, boolean value)
      Description copied from interface: LineReader
      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.

      Specified by:
      option in interface LineReader
      Parameters:
      option - the option to set
      value - the option value
      Returns:
      this LineReader
    • isSet

      public boolean isSet(LineReader.Option option)
      Description copied from interface: LineReader
      Checks if an option is set.

      Options control various aspects of the LineReader's behavior. See the LineReader.Option enum for available options.

      Specified by:
      isSet in interface LineReader
      Parameters:
      option - the option to check
      Returns:
      true if the option is set, false otherwise
    • setOpt

      public void setOpt(LineReader.Option option)
      Description copied from interface: LineReader
      Sets an option to true.

      Options control various aspects of the LineReader's behavior. See the LineReader.Option enum for available options.

      Specified by:
      setOpt in interface LineReader
      Parameters:
      option - the option to set
    • unsetOpt

      public void unsetOpt(LineReader.Option option)
      Description copied from interface: LineReader
      Sets an option to false.

      Options control various aspects of the LineReader's behavior. See the LineReader.Option enum for available options.

      Specified by:
      unsetOpt in interface LineReader
      Parameters:
      option - the option to unset
    • addCommandsInBuffer

      public void addCommandsInBuffer(Collection<String> commands)
      Description copied from interface: LineReader
      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.

      Specified by:
      addCommandsInBuffer in interface LineReader
      Parameters:
      commands - the commands to add to the buffer
    • editAndAddInBuffer

      public void editAndAddInBuffer(Path file) throws Exception
      Description copied from interface: LineReader
      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.

      Specified by:
      editAndAddInBuffer in interface LineReader
      Parameters:
      file - the file to edit, or null to create a temporary file
      Throws:
      Exception - if an error occurs while editing the file
    • getTabWidth

      protected int getTabWidth()
    • finishBuffer

      protected String finishBuffer()
      Clear the buffer and add its contents to the history.
      Returns:
      the former contents of the buffer.
    • finish

      protected String finish(String str)
    • handleSignal

      protected void handleSignal(Terminal.Signal signal)
    • getWidget

      protected Widget getWidget(Object binding)
    • setPrompt

      public void setPrompt(String prompt)
    • setRightPrompt

      public void setRightPrompt(String rightPrompt)
    • setBuffer

      protected void setBuffer(Buffer buffer)
    • setBuffer

      protected void setBuffer(String buffer)
      Set the current buffer's content to the specified String. The visual terminal will be modified to show the current buffer.
      Parameters:
      buffer - the new contents of the buffer.
    • viDeleteChangeYankToRemap

      protected String viDeleteChangeYankToRemap(String 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
    • switchCase

      protected int switchCase(int ch)
    • isInViMoveOperation

      protected boolean isInViMoveOperation()
      Returns:
      true if line reader is in the middle of doing a change-to delete-to or yank-to.
    • isInViChangeOperation

      protected boolean isInViChangeOperation()
    • isInViCmdMode

      protected boolean isInViCmdMode()
    • viForwardChar

      protected boolean viForwardChar()
    • viBackwardChar

      protected boolean viBackwardChar()
    • forwardWord

      protected boolean forwardWord()
    • viForwardWord

      protected boolean viForwardWord()
    • viForwardBlankWord

      protected boolean viForwardBlankWord()
    • emacsForwardWord

      protected boolean emacsForwardWord()
    • viForwardBlankWordEnd

      protected boolean viForwardBlankWordEnd()
    • viForwardWordEnd

      protected boolean viForwardWordEnd()
    • backwardWord

      protected boolean backwardWord()
    • viBackwardWord

      protected boolean viBackwardWord()
    • viBackwardBlankWord

      protected boolean viBackwardBlankWord()
    • viBackwardWordEnd

      protected boolean viBackwardWordEnd()
    • viBackwardBlankWordEnd

      protected boolean viBackwardBlankWordEnd()
    • emacsBackwardWord

      protected boolean emacsBackwardWord()
    • backwardDeleteWord

      protected boolean backwardDeleteWord()
    • viBackwardKillWord

      protected boolean viBackwardKillWord()
    • backwardKillWord

      protected boolean backwardKillWord()
    • copyPrevWord

      protected boolean copyPrevWord()
    • upCaseWord

      protected boolean upCaseWord()
    • downCaseWord

      protected boolean downCaseWord()
    • capitalizeWord

      protected boolean capitalizeWord()
    • deleteWord

      protected boolean deleteWord()
    • killWord

      protected boolean killWord()
    • transposeWords

      protected boolean transposeWords()
    • insertComment

      protected boolean insertComment()
    • viInsertComment

      protected boolean viInsertComment()
    • doInsertComment

      protected boolean doInsertComment(boolean isViMode)
    • viFindNextChar

      protected boolean viFindNextChar()
    • viFindPrevChar

      protected boolean viFindPrevChar()
    • viFindNextCharSkip

      protected boolean viFindNextCharSkip()
    • viFindPrevCharSkip

      protected boolean viFindPrevCharSkip()
    • viRepeatFind

      protected boolean viRepeatFind()
    • viRevRepeatFind

      protected boolean viRevRepeatFind()
    • viHistorySearchForward

      protected boolean viHistorySearchForward()
      Implements vi search ("/" or "?").
      Returns:
      true if the search was successful
    • viHistorySearchBackward

      protected boolean viHistorySearchBackward()
    • viRepeatSearch

      protected boolean viRepeatSearch()
    • viRevRepeatSearch

      protected boolean viRevRepeatSearch()
    • insertCloseCurly

      protected boolean insertCloseCurly()
    • insertCloseParen

      protected boolean insertCloseParen()
    • insertCloseSquare

      protected boolean insertCloseSquare()
    • insertClose

      protected boolean insertClose(String s)
    • viMatchBracket

      protected boolean viMatchBracket()
    • undefinedKey

      protected boolean undefinedKey()
    • doViMatchBracket

      protected boolean doViMatchBracket()
      Implements vi style bracket matching ("%" command). The matching bracket for the current bracket type that you are sitting on is matched.
      Returns:
      true if it worked, false if the cursor was not on a bracket character or if there was no matching bracket.
    • getBracketType

      protected int getBracketType(int 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.
    • transposeChars

      protected boolean transposeChars()
      Performs character transpose. The character prior to the cursor and the character under the cursor are swapped and the cursor is advanced one. Do not cross line breaks.
      Returns:
      true
    • undo

      protected boolean undo()
    • redo

      protected boolean redo()
    • sendBreak

      protected boolean sendBreak()
    • backwardChar

      protected boolean backwardChar()
    • forwardChar

      protected boolean forwardChar()
    • viDigitOrBeginningOfLine

      protected boolean viDigitOrBeginningOfLine()
    • universalArgument

      protected boolean universalArgument()
    • argumentBase

      protected boolean argumentBase()
    • negArgument

      protected boolean negArgument()
    • digitArgument

      protected boolean digitArgument()
    • viDelete

      protected boolean viDelete()
    • viYankTo

      protected boolean viYankTo()
    • viYankWholeLine

      protected boolean viYankWholeLine()
    • viChange

      protected boolean viChange()
    • cleanup

      protected void cleanup()
    • doCleanup

      protected void doCleanup(boolean nl)
    • historyIncrementalSearchForward

      protected boolean historyIncrementalSearchForward()
    • historyIncrementalSearchBackward

      protected boolean historyIncrementalSearchBackward()
    • doSearchHistory

      protected boolean doSearchHistory(boolean backward)
    • historySearchForward

      protected boolean historySearchForward()
    • historySearchBackward

      protected boolean historySearchBackward()
    • searchBackwards

      public int searchBackwards(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(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(String searchTerm, int startIndex, boolean startsWith)
    • searchForwards

      public int searchForwards(String searchTerm, int startIndex, boolean startsWith)
    • searchForwards

      public int searchForwards(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(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.
    • quit

      protected boolean quit()
    • acceptAndHold

      protected boolean acceptAndHold()
    • acceptLineAndDownHistory

      protected boolean acceptLineAndDownHistory()
    • acceptAndInferNextHistory

      protected boolean acceptAndInferNextHistory()
    • acceptLine

      protected boolean acceptLine()
    • selfInsert

      protected boolean selfInsert()
    • selfInsertUnmeta

      protected boolean selfInsertUnmeta()
    • overwriteMode

      protected boolean overwriteMode()
    • beginningOfBufferOrHistory

      protected boolean beginningOfBufferOrHistory()
    • beginningOfHistory

      protected boolean beginningOfHistory()
    • endOfBufferOrHistory

      protected boolean endOfBufferOrHistory()
    • endOfHistory

      protected boolean endOfHistory()
    • beginningOfLineHist

      protected boolean beginningOfLineHist()
    • endOfLineHist

      protected boolean endOfLineHist()
    • upHistory

      protected boolean upHistory()
    • downHistory

      protected boolean downHistory()
    • viUpLineOrHistory

      protected boolean viUpLineOrHistory()
    • viDownLineOrHistory

      protected boolean viDownLineOrHistory()
    • upLine

      protected boolean upLine()
    • downLine

      protected boolean downLine()
    • upLineOrHistory

      protected boolean upLineOrHistory()
    • upLineOrSearch

      protected boolean upLineOrSearch()
    • downLineOrHistory

      protected boolean downLineOrHistory()
    • downLineOrSearch

      protected boolean downLineOrSearch()
    • viCmdMode

      protected boolean viCmdMode()
    • viInsert

      protected boolean viInsert()
    • viAddNext

      protected boolean viAddNext()
    • viAddEol

      protected boolean viAddEol()
    • emacsEditingMode

      protected boolean emacsEditingMode()
    • viChangeWholeLine

      protected boolean viChangeWholeLine()
    • viChangeEol

      protected boolean viChangeEol()
    • viKillEol

      protected boolean viKillEol()
    • quotedInsert

      protected boolean quotedInsert()
    • viJoin

      protected boolean viJoin()
    • viKillWholeLine

      protected boolean viKillWholeLine()
    • viInsertBol

      protected boolean viInsertBol()
    • backwardDeleteChar

      protected boolean backwardDeleteChar()
    • viFirstNonBlank

      protected boolean viFirstNonBlank()
    • viBeginningOfLine

      protected boolean viBeginningOfLine()
    • viEndOfLine

      protected boolean viEndOfLine()
    • beginningOfLine

      protected boolean beginningOfLine()
    • endOfLine

      protected boolean endOfLine()
    • deleteChar

      protected boolean deleteChar()
    • viBackwardDeleteChar

      protected boolean viBackwardDeleteChar()
      Deletes the previous character from the cursor position
      Returns:
      true if it succeeded, false otherwise
    • viDeleteChar

      protected boolean viDeleteChar()
      Deletes the character you are sitting on and sucks the rest of the line in from the right.
      Returns:
      true if it succeeded, false otherwise
    • viSwapCase

      protected boolean viSwapCase()
      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.
      Returns:
      true if it succeeded, false otherwise
    • viReplaceChars

      protected boolean viReplaceChars()
      Implements the vi change character command (in move-mode "r" followed by the character to change to).
      Returns:
      true if it succeeded, false otherwise
    • viChange

      protected boolean viChange(int startPos, int endPos)
    • viDeleteTo

      protected boolean viDeleteTo(int startPos, int endPos)
    • doViDeleteOrChange

      protected boolean doViDeleteOrChange(int startPos, int endPos, boolean isChange)
      Performs the vi "delete-to" action, deleting characters between a given span of the input line.
      Parameters:
      startPos - The start position
      endPos - 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
    • viYankTo

      protected boolean viYankTo(int startPos, int endPos)
      Implement the "vi" yank-to operation. This operation allows you to yank the contents of the current line based upon a move operation, for example "yw" yanks the current word, "3yw" yanks 3 words, etc.
      Parameters:
      startPos - The starting position from which to yank
      endPos - The ending position to which to yank
      Returns:
      true if the yank succeeded
    • viOpenLineAbove

      protected boolean viOpenLineAbove()
    • viOpenLineBelow

      protected boolean viOpenLineBelow()
    • viPutAfter

      protected boolean viPutAfter()
      Pasts the yank buffer to the right of the current cursor position and moves the cursor to the end of the pasted region.
      Returns:
      true
    • viPutBefore

      protected boolean viPutBefore()
    • doLowercaseVersion

      protected boolean doLowercaseVersion()
    • setMarkCommand

      protected boolean setMarkCommand()
    • exchangePointAndMark

      protected boolean exchangePointAndMark()
    • visualMode

      protected boolean visualMode()
    • visualLineMode

      protected boolean visualLineMode()
    • deactivateRegion

      protected boolean deactivateRegion()
    • whatCursorPosition

      protected boolean whatCursorPosition()
    • editAndExecute

      protected boolean editAndExecute()
    • builtinWidgets

      protected Map<String,Widget> builtinWidgets()
    • redisplay

      public boolean redisplay()
    • redisplay

      protected void redisplay(boolean flush)
    • getDisplayedBufferWithPrompts

      public AttributedString getDisplayedBufferWithPrompts(List<AttributedString> secondaryPrompts)
      Compute the full string to be displayed with the left, right and secondary prompts
      Parameters:
      secondaryPrompts - a list to store the secondary prompts
      Returns:
      the displayed string including the buffer, left prompts and the help below
    • insertTab

      protected boolean insertTab()
    • expandHistory

      protected boolean expandHistory()
    • expandWord

      protected boolean expandWord()
    • expandOrComplete

      protected boolean expandOrComplete()
    • expandOrCompletePrefix

      protected boolean expandOrCompletePrefix()
    • completeWord

      protected boolean completeWord()
    • completePrefix

      protected boolean completePrefix()
    • listChoices

      protected boolean listChoices()
    • deleteCharOrList

      protected boolean deleteCharOrList()
    • doComplete

      protected boolean doComplete(LineReaderImpl.CompletionType lst, boolean useMenu, boolean prefix)
    • doComplete

      protected boolean doComplete(LineReaderImpl.CompletionType lst, boolean useMenu, boolean prefix, boolean forSuggestion)
    • wrap

      protected static CompletingParsedLine wrap(ParsedLine line)
    • getCandidateComparator

      protected Comparator<Candidate> getCandidateComparator(boolean caseInsensitive, String word)
    • getOthersGroupName

      protected String getOthersGroupName()
    • getOriginalGroupName

      protected String getOriginalGroupName()
    • getGroupComparator

      protected Comparator<String> getGroupComparator()
    • nextBindingIsComplete

      protected boolean nextBindingIsComplete()
    • doMenu

      protected boolean doMenu(List<Candidate> original, String completed, BiFunction<CharSequence,Boolean,CharSequence> escaper)
    • clearChoices

      protected boolean clearChoices()
    • doList

      protected boolean doList(List<Candidate> possible, String completed, boolean runLoop, BiFunction<CharSequence,Boolean,CharSequence> escaper)
    • doList

      protected boolean doList(List<Candidate> possible, String completed, boolean runLoop, BiFunction<CharSequence,Boolean,CharSequence> escaper, boolean forSuggestion)
    • computePost

      protected LineReaderImpl.PostResult computePost(List<Candidate> possible, Candidate selection, List<Candidate> ordered, String completed)
    • computePost

      protected LineReaderImpl.PostResult computePost(List<Candidate> possible, Candidate selection, List<Candidate> ordered, String completed, Function<String,Integer> wcwidth, int width, boolean autoGroup, boolean groupName, boolean rowsFirst)
    • toColumns

      protected LineReaderImpl.PostResult toColumns(List<Object> items, Candidate selection, String completed, Function<String,Integer> wcwidth, int width, boolean rowsFirst)
    • toColumns

      protected void toColumns(Object items, int width, int maxWidth, AttributedStringBuilder sb, Candidate selection, String completed, boolean rowsFirst, boolean doMenuList, int[] out)
    • getCompletionStyleStarting

      protected AttributedStyle getCompletionStyleStarting(boolean menuList)
    • getCompletionStyleDescription

      protected AttributedStyle getCompletionStyleDescription(boolean menuList)
    • getCompletionStyleGroup

      protected AttributedStyle getCompletionStyleGroup(boolean menuList)
    • getCompletionStyleSelection

      protected AttributedStyle getCompletionStyleSelection(boolean menuList)
    • getCompletionStyleBackground

      protected AttributedStyle getCompletionStyleBackground(boolean menuList)
    • getCompletionStyleStarting

      protected AttributedStyle getCompletionStyleStarting()
    • getCompletionStyleDescription

      protected AttributedStyle getCompletionStyleDescription()
    • getCompletionStyleGroup

      protected AttributedStyle getCompletionStyleGroup()
    • getCompletionStyleSelection

      protected AttributedStyle getCompletionStyleSelection()
    • getCompletionStyleBackground

      protected AttributedStyle getCompletionStyleBackground()
    • getCompletionStyleListStarting

      protected AttributedStyle getCompletionStyleListStarting()
    • getCompletionStyleListDescription

      protected AttributedStyle getCompletionStyleListDescription()
    • getCompletionStyleListGroup

      protected AttributedStyle getCompletionStyleListGroup()
    • getCompletionStyleListSelection

      protected AttributedStyle getCompletionStyleListSelection()
    • getCompletionStyleListBackground

      protected AttributedStyle getCompletionStyleListBackground()
    • getCompletionStyle

      protected AttributedStyle getCompletionStyle(String name, String value)
    • buildStyle

      protected AttributedStyle buildStyle(String str)
    • moveHistory

      protected 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.
      Parameters:
      next - If true, move forward
      count - The number of entries to move
      Returns:
      true if the move was successful
    • moveHistory

      protected boolean moveHistory(boolean next)
      Move up or down the history tree.
      Parameters:
      next - true to go to the next, false for the previous.
      Returns:
      true if successful, false otherwise
    • killBuffer

      protected boolean killBuffer()
    • killWholeLine

      protected boolean killWholeLine()
    • killLine

      public boolean killLine()
      Kill the buffer ahead of the current cursor position.
      Returns:
      true if successful
    • backwardKillLine

      public boolean backwardKillLine()
    • killRegion

      public boolean killRegion()
    • copyRegionAsKill

      public boolean copyRegionAsKill()
    • yank

      public boolean yank()
    • yankPop

      public boolean yankPop()
    • mouse

      public boolean mouse()
    • beginPaste

      public boolean beginPaste()
    • focusIn

      public boolean focusIn()
    • focusOut

      public boolean focusOut()
    • clear

      public boolean clear()
      Clean the used display
      Returns:
      true
    • clearScreen

      public boolean clearScreen()
      Clear the screen by issuing the ANSI "clear screen" code.
      Returns:
      true
    • beep

      public boolean beep()
      Issue an audible keyboard bell.
      Returns:
      true
    • isDelimiter

      protected boolean isDelimiter(int 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

      protected boolean isWhitespace(int c)
      Checks to see if a character is a whitespace character. Currently this delegates to Character.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
    • isViAlphaNum

      protected boolean isViAlphaNum(int c)
    • isAlpha

      protected boolean isAlpha(int c)
    • isWord

      protected boolean isWord(int c)
    • defaultKeyMaps

      public Map<String,KeyMap<Binding>> defaultKeyMaps()
      Description copied from interface: LineReader
      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.

      Specified by:
      defaultKeyMaps in interface LineReader
      Returns:
      a map of key map names to key maps
    • emacs

      public KeyMap<Binding> emacs()
    • viInsertion

      public KeyMap<Binding> viInsertion()
    • viCmd

      public KeyMap<Binding> viCmd()
    • safe

      public KeyMap<Binding> safe()
    • dumb

      public KeyMap<Binding> dumb()
    • visual

      public KeyMap<Binding> visual()
    • viOpp

      public KeyMap<Binding> viOpp()
    • zeroOut

      public void zeroOut()
      Description copied from interface: LineReader
      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.

      Specified by:
      zeroOut in interface LineReader