Class Prompt.PromptBuilder
java.lang.Object
org.aesh.readline.prompt.Prompt.PromptBuilder
- Enclosing class:
Prompt
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):
characters(List<TerminalCharacter>)terminalString(TerminalString)promptCodePoints(int[])promptString(String), optionally combined withansiString
Example usage:
Prompt p = Prompt.builder()
.message("$ ")
.mask('*')
.build();
- Author:
- Ståle W. Pedersen
-
Method Summary
Modifier and TypeMethodDescriptionSets the ANSI-formatted string for display.build()Builds a newPromptinstance from the configured parameters.characters(List<org.aesh.terminal.formatting.TerminalCharacter> characters) Sets the prompt from a list of individually formattedTerminalCharacters.Adds a line to a multi-line prompt.mask(char mask) Sets the mask character for hiding user input (e.g., for passwords).Sets the prompt text.promptCodePoints(int[] codePoints) Sets the prompt as an array of Unicode code points.rightPrompt(String rightPrompt) Sets the right prompt string, displayed right-aligned on the prompt line.terminalString(org.aesh.terminal.formatting.TerminalString terminalString) Sets the prompt from aTerminalStringwith ANSI formatting.
-
Method Details
-
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
Sets the prompt text.- Parameters:
prompt- the prompt text- Returns:
- this builder
-
ansi
Sets the ANSI-formatted string for display. This is used in combination withmessage(String)to provide a separate display representation with ANSI escape codes.- Parameters:
ansiString- the ANSI-formatted string- Returns:
- this builder
-
mask
Sets the mask character for hiding user input (e.g., for passwords).- Parameters:
mask- the masking character- Returns:
- this builder
-
promptCodePoints
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 aTerminalStringwith ANSI formatting.- Parameters:
terminalString- the terminal string containing the prompt- Returns:
- this builder
-
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 formattedTerminalCharacters.- Parameters:
characters- the list of terminal characters- Returns:
- this builder
-
build
-