Class Prompt.PromptBuilder

java.lang.Object
org.aesh.readline.prompt.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();
Author:
Ståle W. Pedersen
  • Method Details

    • line

      public Prompt.PromptBuilder line(String line)
      Adds a line to a multi-line prompt.

      Lines are displayed in order, with the last line being the input line where the cursor appears. Each line can contain ANSI escape codes which are auto-detected for length calculation.

      Example:

      Prompt.builder()
              .line("myapp on main via ☕ v21")
              .line("❯ ")
              .build();
      
      Parameters:
      line - the line text
      Returns:
      this builder
    • 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(org.aesh.terminal.formatting.TerminalString terminalString)
      Sets the prompt from a TerminalString with ANSI formatting.
      Parameters:
      terminalString - the terminal string containing the prompt
      Returns:
      this builder
    • rightPrompt

      public Prompt.PromptBuilder rightPrompt(String rightPrompt)
      Sets the right prompt string, displayed right-aligned on the prompt line.
      Parameters:
      rightPrompt - the right prompt string
      Returns:
      this builder
    • characters

      public Prompt.PromptBuilder characters(List<org.aesh.terminal.formatting.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