Class Prompt

java.lang.Object
org.aesh.readline.Prompt

public class Prompt extends Object
The Prompt: If created with a String value that value will be the prompt with the default back and foreground colors. If created with TerminalCharacters the colors can be set individually.
Author:
Ståle W. Pedersen
  • Constructor Details

    • Prompt

      public Prompt()
      Creates an empty prompt.
    • Prompt

      public Prompt(String prompt)
      Creates a prompt with the specified text.
      Parameters:
      prompt - the prompt text, or null for an empty prompt
    • Prompt

      public Prompt(Prompt prompt)
      Creates a copy of the specified prompt.
      Parameters:
      prompt - the prompt to copy
    • Prompt

      public Prompt(String prompt, String ansiString)
      Creates a prompt with the specified text and ANSI formatting.
      Parameters:
      prompt - the prompt text for length calculation, or null for an empty prompt
      ansiString - the ANSI-formatted string for display
    • Prompt

      public Prompt(String prompt, Character mask)
      Creates a prompt with the specified text and input masking character.
      Parameters:
      prompt - the prompt text, or null for an empty prompt
      mask - the character to use for masking input (e.g., for passwords)
    • Prompt

      public Prompt(String prompt, String ansiString, Character mask)
      Creates a prompt with the specified text, ANSI formatting, and input masking character.
      Parameters:
      prompt - the prompt text for length calculation, or null for an empty prompt
      ansiString - the ANSI-formatted string for display
      mask - the character to use for masking input (e.g., for passwords)
    • Prompt

      public Prompt(int[] prompt, Character mask)
      Creates a prompt with the specified code points and input masking character.
      Parameters:
      prompt - the prompt as an array of Unicode code points, or null for an empty prompt
      mask - the character to use for masking input (e.g., for passwords)
    • Prompt

      public Prompt(TerminalString terminalString)
      Creates a prompt from a TerminalString with ANSI formatting.
      Parameters:
      terminalString - the terminal string containing the prompt, or null for an empty prompt
    • Prompt

      public Prompt(List<TerminalCharacter> characters)
      Creates a prompt from a list of terminal characters with individual formatting.
      Parameters:
      characters - the list of terminal characters that make up the prompt
    • Prompt

      public Prompt(List<TerminalCharacter> characters, Character mask)
      Creates a prompt from a list of terminal characters with individual formatting and an input masking character.
      Parameters:
      characters - the list of terminal characters that make up the prompt
      mask - the character to use for masking input (e.g., for passwords)
  • Method Details

    • getMask

      public Character getMask()
      Returns the masking character used for hiding input.
      Returns:
      the mask character, or null if masking is not enabled
    • isMasking

      public boolean isMasking()
      Checks if input masking is enabled.
      Returns:
      true if a mask character is set, false otherwise
    • getPromptCharacters

      public int[] getPromptCharacters()
      Returns the prompt as an int array of characters.
      Returns:
      the prompt characters as an int array
    • getPromptAsString

      @Deprecated public int[] getPromptAsString()
      Deprecated.
      Use getPromptCharacters() instead. The name is misleading since this returns int[], not String.
      Returns the prompt as an int array of characters.
      Returns:
      the prompt characters as an int array
    • getLength

      public int getLength()
      Returns the length of the prompt in characters.
      Returns:
      the prompt length
    • hasANSI

      public boolean hasANSI()
      Checks if the prompt has ANSI formatting.
      Returns:
      true if ANSI formatting is present, false otherwise
    • getANSI

      public int[] getANSI()
      Returns the ANSI-formatted prompt string, or the plain prompt if no ANSI formatting exists.
      Returns:
      the ANSI string as code points, or the plain prompt if no ANSI formatting
    • copy

      public Prompt copy()
      Creates a copy of this prompt.
      Returns:
      a new Prompt instance with the same values
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • builder

      public static Prompt.PromptBuilder builder()
      Creates a new PromptBuilder for constructing Prompt instances.
      Returns:
      a new PromptBuilder