Class Readline

java.lang.Object
org.aesh.readline.Readline

public class Readline extends Object
Readline is a simple way to read a single input line from the terminal/shell/console. Readline reads/writes from/to a Connection.

Readline is thread safe and will not accept new readline(org.aesh.terminal.Connection, java.lang.String, java.util.function.Consumer<java.lang.String>) calls while currently reading input.

  • Constructor Summary

    Constructors
    Constructor
    Description
    Creates a new Readline instance with default edit mode, in-memory history, and simple completion handler.
    Readline(EditMode editMode)
    Creates a new Readline instance with the specified edit mode and in-memory history.
    Readline(EditMode editMode, History history, CompletionHandler<?> completionHandler)
    Creates a new Readline instance with the specified edit mode, history, and completion handler.
  • Method Summary

    Modifier and Type
    Method
    Description
    protected InputProcessor
    Returns the current input processor.
    void
    Reads a line of input using a ReadlineRequest that encapsulates all parameters.
    void
    readline(org.aesh.terminal.Connection conn, String prompt, Consumer<String> requestHandler)
    Reads a line of input from the connection with a string prompt.
    void
    readline(org.aesh.terminal.Connection conn, String prompt, Consumer<String> requestHandler, List<org.aesh.readline.completion.Completion> completions)
    Reads a line of input from the connection with a string prompt and completions.
    void
    readline(org.aesh.terminal.Connection conn, org.aesh.readline.prompt.Prompt prompt, Consumer<String> requestHandler)
    Reads a line of input from the connection with a Prompt object.
    void
    readline(org.aesh.terminal.Connection conn, org.aesh.readline.prompt.Prompt prompt, Consumer<String> requestHandler, List<org.aesh.readline.completion.Completion> completions)
    Reads a line of input from the connection with a Prompt object and completions.
    void
    setSuggestionProvider(org.aesh.readline.suggestion.SuggestionProvider provider)
    Sets the suggestion provider for inline ghost text.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • Readline

      public Readline()
      Creates a new Readline instance with default edit mode, in-memory history, and simple completion handler.
    • Readline

      public Readline(EditMode editMode)
      Creates a new Readline instance with the specified edit mode and in-memory history.
      Parameters:
      editMode - the edit mode to use (e.g., Emacs or Vi mode)
    • Readline

      public Readline(EditMode editMode, History history, CompletionHandler<?> completionHandler)
      Creates a new Readline instance with the specified edit mode, history, and completion handler.
      Parameters:
      editMode - the edit mode to use (e.g., Emacs or Vi mode)
      history - the history implementation to use for command history
      completionHandler - the completion handler for tab completion, or null for default
  • Method Details

    • setSuggestionProvider

      public void setSuggestionProvider(org.aesh.readline.suggestion.SuggestionProvider provider)
      Sets the suggestion provider for inline ghost text.
      Parameters:
      provider - the suggestion provider
    • getInputProcessor

      protected InputProcessor getInputProcessor()
      Returns the current input processor.
      Returns:
      the input processor, or null if not currently reading input
    • readline

      public void readline(org.aesh.terminal.Connection conn, String prompt, Consumer<String> requestHandler)
      Reads a line of input from the connection with a string prompt.
      Parameters:
      conn - the terminal connection to read from
      prompt - the prompt string to display
      requestHandler - the callback to receive the completed input line
    • readline

      public void readline(org.aesh.terminal.Connection conn, String prompt, Consumer<String> requestHandler, List<org.aesh.readline.completion.Completion> completions)
      Reads a line of input from the connection with a string prompt and completions.
      Parameters:
      conn - the terminal connection to read from
      prompt - the prompt string to display
      requestHandler - the callback to receive the completed input line
      completions - the list of completions for tab completion
    • readline

      public void readline(org.aesh.terminal.Connection conn, org.aesh.readline.prompt.Prompt prompt, Consumer<String> requestHandler)
      Reads a line of input from the connection with a Prompt object.
      Parameters:
      conn - the terminal connection to read from
      prompt - the prompt to display
      requestHandler - the callback to receive the completed input line
    • readline

      public void readline(org.aesh.terminal.Connection conn, org.aesh.readline.prompt.Prompt prompt, Consumer<String> requestHandler, List<org.aesh.readline.completion.Completion> completions)
      Reads a line of input from the connection with a Prompt object and completions.
      Parameters:
      conn - the terminal connection to read from
      prompt - the prompt to display
      requestHandler - the callback to receive the completed input line
      completions - the list of completions for tab completion
    • readline

      public void readline(ReadlineRequest request)
      Reads a line of input using a ReadlineRequest that encapsulates all parameters. This is the preferred way to invoke readline when optional parameters are needed.

      Example usage:

      
       ReadlineRequest request = ReadlineRequest.builder()
               .connection(conn)
               .prompt(new Prompt("$ "))
               .requestHandler(line -> System.out.println("Got: " + line))
               .completions(myCompletions)
               .history(myHistory)
               .build();
       readline.readline(request);
       
      Parameters:
      request - the readline request containing all parameters
      Throws:
      IllegalStateException - if already reading a line