- java.lang.Object
-
- org.jline.prompt.impl.DefaultSearchBuilder<T>
-
- All Implemented Interfaces:
BaseBuilder<SearchBuilder<T>>,SearchBuilder<T>
public class DefaultSearchBuilder<T> extends java.lang.Object implements SearchBuilder<T>
Default implementation of SearchBuilder.
-
-
Constructor Summary
Constructors Constructor Description DefaultSearchBuilder(PromptBuilder parent)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description PromptBuilderaddPrompt()Complete the configuration of this prompt and add it to the parent builder.SearchBuilder<T>displayFunction(java.util.function.Function<T,java.lang.String> displayFunction)Set the display function.SearchBuilder<T>filter(java.util.function.Function<java.lang.String,java.lang.String> filter)Set a filter function that modifies the actual returned value.SearchBuilder<T>maxResults(int maxResults)Set the maximum number of results.SearchBuilder<T>message(java.lang.String message)Set the message displayed to the user for this prompt.SearchBuilder<T>minSearchLength(int minSearchLength)Set the minimum search length.SearchBuilder<T>name(java.lang.String name)Set the unique identifier for this prompt.SearchBuilder<T>placeholder(java.lang.String placeholder)Set the placeholder text.SearchBuilder<T>searchFunction(java.util.function.Function<java.lang.String,java.util.List<T>> searchFunction)Set the search function.SearchBuilder<T>transformer(java.util.function.Function<java.lang.String,java.lang.String> transformer)Set a transformer function that modifies how the answer is displayed after submission.SearchBuilder<T>valueFunction(java.util.function.Function<T,java.lang.String> valueFunction)Set the value function.
-
-
-
Constructor Detail
-
DefaultSearchBuilder
public DefaultSearchBuilder(PromptBuilder parent)
-
-
Method Detail
-
name
public SearchBuilder<T> name(java.lang.String name)
Description copied from interface:BaseBuilderSet the unique identifier for this prompt.The name serves as the key in the result map returned by
Prompter.prompt(java.util.List<org.jline.utils.AttributedString>, java.util.List<? extends org.jline.prompt.Prompt>). It must be unique within a single prompt session to avoid conflicts.Naming Guidelines:
- Use descriptive, lowercase names with underscores:
"user_name","file_path" - Avoid spaces and special characters
- Keep names concise but meaningful
- Use consistent naming conventions across your application
Example:
builder.createInputPrompt() .name("email_address") // Used as key in results map .message("Enter your email:") .addPrompt(); // Later access the result InputResult emailResult = (InputResult) results.get("email_address");- Specified by:
namein interfaceBaseBuilder<T>- Parameters:
name- the unique identifier for this prompt (required, non-null, non-empty)- Returns:
- this builder instance for method chaining
- Use descriptive, lowercase names with underscores:
-
message
public SearchBuilder<T> message(java.lang.String message)
Description copied from interface:BaseBuilderSet the message displayed to the user for this prompt.The message is the primary text that explains what the user should do. It should be clear, concise, and provide sufficient context for the user to understand what input is expected.
Message Guidelines:
- Use clear, actionable language: "Select your preferred option"
- End with appropriate punctuation (colon for selections, question mark for questions)
- Keep messages concise but informative
- Consider the terminal width for longer messages
Examples:
- List prompt:
"Choose your preferred IDE:" - Input prompt:
"Enter your full name:" - Confirm prompt:
"Do you want to continue?" - Checkbox prompt:
"Select features to enable:"
- Specified by:
messagein interfaceBaseBuilder<T>- Parameters:
message- the message to display to the user (required, non-null, non-empty)- Returns:
- this builder instance for method chaining
-
searchFunction
public SearchBuilder<T> searchFunction(java.util.function.Function<java.lang.String,java.util.List<T>> searchFunction)
Description copied from interface:SearchBuilderSet the search function.- Specified by:
searchFunctionin interfaceSearchBuilder<T>- Parameters:
searchFunction- the function to search items- Returns:
- this builder
-
displayFunction
public SearchBuilder<T> displayFunction(java.util.function.Function<T,java.lang.String> displayFunction)
Description copied from interface:SearchBuilderSet the display function.- Specified by:
displayFunctionin interfaceSearchBuilder<T>- Parameters:
displayFunction- the function to convert items to display strings- Returns:
- this builder
-
valueFunction
public SearchBuilder<T> valueFunction(java.util.function.Function<T,java.lang.String> valueFunction)
Description copied from interface:SearchBuilderSet the value function.- Specified by:
valueFunctionin interfaceSearchBuilder<T>- Parameters:
valueFunction- the function to convert items to values- Returns:
- this builder
-
placeholder
public SearchBuilder<T> placeholder(java.lang.String placeholder)
Description copied from interface:SearchBuilderSet the placeholder text.- Specified by:
placeholderin interfaceSearchBuilder<T>- Parameters:
placeholder- the placeholder text- Returns:
- this builder
-
minSearchLength
public SearchBuilder<T> minSearchLength(int minSearchLength)
Description copied from interface:SearchBuilderSet the minimum search length.- Specified by:
minSearchLengthin interfaceSearchBuilder<T>- Parameters:
minSearchLength- the minimum number of characters before searching- Returns:
- this builder
-
maxResults
public SearchBuilder<T> maxResults(int maxResults)
Description copied from interface:SearchBuilderSet the maximum number of results.- Specified by:
maxResultsin interfaceSearchBuilder<T>- Parameters:
maxResults- the maximum results to display- Returns:
- this builder
-
transformer
public SearchBuilder<T> transformer(java.util.function.Function<java.lang.String,java.lang.String> transformer)
Description copied from interface:BaseBuilderSet a transformer function that modifies how the answer is displayed after submission. This does not change the actual returned value. For example, a password prompt might transform the answer to "***".- Specified by:
transformerin interfaceBaseBuilder<T>- Parameters:
transformer- the transformer function- Returns:
- this builder instance for method chaining
-
filter
public SearchBuilder<T> filter(java.util.function.Function<java.lang.String,java.lang.String> filter)
Description copied from interface:BaseBuilderSet a filter function that modifies the actual returned value. This changes the value stored in the result map. For example, trimming whitespace or converting to lowercase.- Specified by:
filterin interfaceBaseBuilder<T>- Parameters:
filter- the filter function- Returns:
- this builder instance for method chaining
-
addPrompt
public PromptBuilder addPrompt()
Description copied from interface:BaseBuilderComplete the configuration of this prompt and add it to the parent builder.This method finalizes the current prompt configuration, validates that all required fields are set, creates the prompt instance, and adds it to the parent
PromptBuilder. After calling this method, you can continue adding more prompts or callPromptBuilder.build()to create the final list.Validation:
This method typically validates that:
- The prompt name is set and unique
- The message is set and non-empty
- Any prompt-specific requirements are met (e.g., list items are added)
Example Usage:
PromptBuilder builder = prompter.newBuilder(); builder.createListPrompt() .name("color") .message("Choose a color:") .newItem("red").text("Red").add() .newItem("blue").text("Blue").add() .addPrompt() // Completes this prompt and returns to builder .createConfirmPrompt() .name("confirm") .message("Are you sure?") .addPrompt(); // Completes second prompt List<Prompt> prompts = builder.build();- Specified by:
addPromptin interfaceBaseBuilder<T>- Returns:
- the parent
PromptBuilderfor continued prompt configuration - See Also:
PromptBuilder.build()
-
-