Class Prompt
java.lang.Object
org.aesh.readline.prompt.Prompt
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 ClassesModifier and TypeClassDescriptionstatic classBuilder for creatingPromptinstances with a fluent API. -
Constructor Summary
ConstructorsConstructorDescriptionPrompt()Creates an empty prompt.Creates a prompt with the specified code points and input masking character.Creates a prompt with the specified text.Creates a prompt with the specified text and input masking character.Creates a prompt with the specified text and ANSI formatting.Creates a prompt with the specified text, ANSI formatting, and input masking character.Creates a prompt from a list of terminal characters with individual formatting.Creates a prompt from a list of terminal characters with individual formatting and an input masking character.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 TypeMethodDescriptionstatic Prompt.PromptBuilderbuilder()Creates a new PromptBuilder for constructing Prompt instances.copy()Creates a copy of this prompt.booleanint[]getANSI()Returns the ANSI-formatted prompt string, or the plain prompt if no ANSI formatting exists.intDeprecated.getMask()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.booleanhasANSI()Checks if the prompt has ANSI formatting.inthashCode()booleanChecks if input masking is enabled.intlength()Returns the visible length of the prompt's input line (last line).intReturns the number of lines in the prompt.voidsetRightPrompt(String rightPrompt) Sets the right prompt string.
-
Constructor Details
-
Prompt
public Prompt()Creates an empty prompt. -
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
Creates a copy of the specified prompt.- Parameters:
prompt- the prompt to copy
-
Prompt
-
Prompt
-
Prompt
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 promptansiString- the ANSI-formatted string for displaymask- the character to use for masking input (e.g., for passwords)
-
Prompt
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 promptmask- 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
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
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 promptmask- the character to use for masking input (e.g., for passwords)
-
-
Method Details
-
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.Uselength()insteadReturns 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
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
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
Creates a copy of this prompt.- Returns:
- a new Prompt instance with the same values
-
equals
-
hashCode
-
builder
Creates a new PromptBuilder for constructing Prompt instances.- Returns:
- a new PromptBuilder
-
length()instead