Class Widgets

java.lang.Object
org.jline.widget.Widgets
Direct Known Subclasses:
AutopairWidgets, AutosuggestionWidgets, TailTipWidgets

public abstract class Widgets extends Object
Base class for creating custom widgets for JLine's LineReader. This abstract class provides methods for creating, managing, and interacting with widgets in JLine. Widgets are reusable components that can be bound to key sequences and provide specific functionality when invoked. Custom widget implementations should extend this class to leverage its utility methods for widget management.
  • Field Details

  • Constructor Details

    • Widgets

      public Widgets(LineReader reader)
      Creates a new Widgets instance for the specified LineReader.
      Parameters:
      reader - the LineReader to associate with these widgets
  • Method Details

    • addWidget

      public void addWidget(String name, Widget widget)
      Add widget to the LineReader
      Parameters:
      name - the name of widget
      widget - widget
    • callWidget

      public void callWidget(String name)
      Call widget. System widget will be call if the name does not start with '_' or ends with '-toggle' i.e. '.' will be added at the beginning of the name.
      Parameters:
      name - widget name
    • executeWidget

      public void executeWidget(String name)
      Bind widget to ctrl-alt-x and execute it
      Parameters:
      name - widget name
    • aliasWidget

      public void aliasWidget(String orig, String alias)
      Create alias to widget
      Parameters:
      orig - widget original name
      alias - alias name
    • getWidget

      public String getWidget(String name)
      Resolve widget name if its alias is given as method parameter. i.e. both method calls getWidget("yank") and getWidget(".yank") will return string ".yank"
      Parameters:
      name - widget name or alias
      Returns:
      widget name
    • existsWidget

      public boolean existsWidget(String name)
      Test if widget exists
      Parameters:
      name - widget name or its alias
      Returns:
      true if widget exists
    • parser

      public Parser parser()
      Get lineReader's parser
      Returns:
      The parser
    • getKeyMap

      public KeyMap<Binding> getKeyMap()
      Get lineReader's Main KeyMap
      Returns:
      The KeyMap
    • buffer

      public Buffer buffer()
      Get lineReader's buffer
      Returns:
      The buffer
    • replaceBuffer

      public void replaceBuffer(Buffer buffer)
      Replace lineReader buffer
      Parameters:
      buffer - buffer that will be copied to the LineReader Buffer
    • args

      public List<String> args()
      Parse lineReader buffer and returns its arguments
      Returns:
      command line arguments
    • prevChar

      public String prevChar()
      Access lineReader buffer and return its previous character
      Returns:
      previous character
    • currChar

      public String currChar()
      Access lineReader's buffer and return its current character
      Returns:
      current character
    • lastBinding

      public String lastBinding()
      Get lineReader's last binding
      Returns:
      last binding
    • putString

      public void putString(String string)
      Write the string parameter to the lineReader's buffer
      Parameters:
      string - string to be written
    • tailTip

      public String tailTip()
      Get lineReader's command hint
      Returns:
      Command hint.
    • setTailTip

      public void setTailTip(String tailTip)
      Set lineReader's command hint to be added in the command line
      Parameters:
      tailTip - command hint
    • setErrorPattern

      public void setErrorPattern(Pattern errorPattern)
      Set errorPattern to the lineReader's highlighter
      Parameters:
      errorPattern - error pattern
    • setErrorIndex

      public void setErrorIndex(int errorIndex)
      Set errorIndex to the lineReader's highlighter
      Parameters:
      errorIndex - error index
    • clearTailTip

      public void clearTailTip()
      Clears command line command hint
    • setSuggestionType

      public void setSuggestionType(LineReader.SuggestionType type)
      Set lineReader's autosuggestion type
      Parameters:
      type - autosuggestion type
    • setDescription

      public void setDescription(List<AttributedString> desc)
      Set description text to the terminal status bar
      Parameters:
      desc - description text
    • clearDescription

      public void clearDescription()
      Clears terminal status bar
    • destroyDescription

      public void destroyDescription()
      Remove terminal status bar