Class Prompt.PromptBuilder

java.lang.Object
org.aesh.readline.Prompt.PromptBuilder
Enclosing class:
Prompt

public static class Prompt.PromptBuilder extends Object
Builder for creating Prompt instances with a fluent API.

The builder supports all the input combinations that the Prompt constructors accept. When multiple prompt sources are set, the precedence is (highest to lowest):

  1. characters (List<TerminalCharacter>)
  2. terminalString (TerminalString)
  3. promptCodePoints (int[])
  4. promptString (String), optionally combined with ansiString

Example usage:


 Prompt p = Prompt.builder()
         .message("$ ")
         .mask('*')
         .build();
 
  • Method Details

    • message

      public Prompt.PromptBuilder message(String prompt)
      Sets the prompt text.
      Parameters:
      prompt - the prompt text
      Returns:
      this builder
    • ansi

      public Prompt.PromptBuilder ansi(String ansiString)
      Sets the ANSI-formatted string for display. This is used in combination with message(String) to provide a separate display representation with ANSI escape codes.
      Parameters:
      ansiString - the ANSI-formatted string
      Returns:
      this builder
    • mask

      public Prompt.PromptBuilder mask(char mask)
      Sets the mask character for hiding user input (e.g., for passwords).
      Parameters:
      mask - the masking character
      Returns:
      this builder
    • promptCodePoints

      public Prompt.PromptBuilder promptCodePoints(int[] codePoints)
      Sets the prompt as an array of Unicode code points.
      Parameters:
      codePoints - the prompt code points
      Returns:
      this builder
    • terminalString

      public Prompt.PromptBuilder terminalString(TerminalString terminalString)
      Sets the prompt from a TerminalString with ANSI formatting.
      Parameters:
      terminalString - the terminal string containing the prompt
      Returns:
      this builder
    • characters

      public Prompt.PromptBuilder characters(List<TerminalCharacter> characters)
      Sets the prompt from a list of individually formatted TerminalCharacters.
      Parameters:
      characters - the list of terminal characters
      Returns:
      this builder
    • build

      public Prompt build()
      Builds a new Prompt instance from the configured parameters.

      The builder selects the appropriate constructor based on which fields have been set, using the precedence order: characters, terminalString, promptCodePoints, promptString.

      Returns:
      a new Prompt instance