Class DefaultExpander

java.lang.Object
org.jline.reader.impl.DefaultExpander
All Implemented Interfaces:
Expander

public class DefaultExpander extends Object implements Expander
Default implementation of the Expander interface.

This expander provides functionality for expanding special syntax in command lines, including:

  • History expansions (e.g., !!, !$, !n, etc.)
  • Variable expansions (e.g., $HOME, ${PATH})

The history expansion syntax is similar to that used in Bash and other shells, allowing users to reference and reuse previous commands or parts of commands.

The expander is used by the LineReader to process the command line after the user has accepted it but before it is executed or added to the history.

See Also:
  • Constructor Details

    • DefaultExpander

      public DefaultExpander()
  • Method Details

    • expandHistory

      public String expandHistory(History history, String line)
      Expand event designator such as !!, !#, !3, etc... See http://www.gnu.org/software/bash/manual/html_node/Event-Designators.html
      Specified by:
      expandHistory in interface Expander
      Parameters:
      history - the command history to use for expansion
      line - the input line containing history references
      Returns:
      the line with history references expanded
    • expandVar

      public String expandVar(String word)
      Description copied from interface: Expander
      Expands variables in the input word.

      This method processes variable references such as $VAR or ${VAR}, replacing them with their values. The specific syntax and behavior depends on the implementation.

      Specified by:
      expandVar in interface Expander
      Parameters:
      word - the word containing variable references
      Returns:
      the word with variables expanded
    • searchBackwards

      protected int searchBackwards(History history, String searchTerm, int startIndex, boolean startsWith)