Class Prompt

java.lang.Object
org.aesh.readline.prompt.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
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static class 
    Builder for creating Prompt instances with a fluent API.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Creates an empty prompt.
    Prompt(int[] prompt, Character mask)
    Creates a prompt with the specified code points and input masking character.
    Prompt(String prompt)
    Creates a prompt with the specified text.
    Prompt(String prompt, Character mask)
    Creates a prompt with the specified text and input masking character.
    Prompt(String prompt, String ansiString)
    Creates a prompt with the specified text and ANSI formatting.
    Prompt(String prompt, String ansiString, Character mask)
    Creates a prompt with the specified text, ANSI formatting, and input masking character.
    Prompt(List<org.aesh.terminal.formatting.TerminalCharacter> characters)
    Creates a prompt from a list of terminal characters with individual formatting.
    Prompt(List<org.aesh.terminal.formatting.TerminalCharacter> characters, Character mask)
    Creates a prompt from a list of terminal characters with individual formatting and an input masking character.
    Prompt(Prompt prompt)
    Creates a copy of the specified prompt.
    Prompt(org.aesh.terminal.formatting.TerminalString terminalString)
    Creates a prompt from a TerminalString with ANSI formatting.
  • Method Summary

    Modifier and Type
    Method
    Description
    Creates a new PromptBuilder for constructing Prompt instances.
    Creates a copy of this prompt.
    boolean
     
    int[]
    Returns the ANSI-formatted prompt string, or the plain prompt if no ANSI formatting exists.
    int
    Deprecated.
    Use length() instead
    Returns the masking character used for hiding input.
    int[]
    Returns the prompt as an int array of characters.
    Returns the right prompt string, or null if not set.
    boolean
    Checks if the prompt has ANSI formatting.
    int
     
    boolean
    Checks if input masking is enabled.
    int
    Returns the visible length of the prompt's input line (last line).
    int
    Returns the number of lines in the prompt.
    void
    setRightPrompt(String rightPrompt)
    Sets the right prompt string.

    Methods inherited from class Object

    clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
  • 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. If the string contains ANSI escape codes, the visible length is calculated automatically (stripping ANSI codes) and the full string is stored as the ANSI display string.
    • 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(org.aesh.terminal.formatting.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<org.aesh.terminal.formatting.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<org.aesh.terminal.formatting.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
    • length

      public int length()
      Returns the visible length of the prompt's input line (last line). For multi-line prompts, this is the length of the last line only, which is what matters for cursor positioning.
      Returns:
      the input line length
    • getLength

      @Deprecated public int getLength()
      Deprecated.
      Use length() instead
      Returns the visible length of the prompt's input line.
      Returns:
      the input line length
    • lineCount

      public int lineCount()
      Returns the number of lines in the prompt. Single-line prompts return 1. Multi-line prompts return the number of lines (including the input line).
      Returns:
      the number of prompt lines
    • 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
    • getRightPrompt

      public String getRightPrompt()
      Returns the right prompt string, or null if not set. The right prompt is displayed right-aligned on the prompt line.
      Returns:
      the right prompt string, or null
    • setRightPrompt

      public void setRightPrompt(String rightPrompt)
      Sets the right prompt string. The right prompt is displayed right-aligned on the prompt line and disappears when the input grows too long.
      Parameters:
      rightPrompt - the right prompt string, or null to disable
    • 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