Class DefaultEditorBuilder

java.lang.Object
org.jline.prompt.impl.DefaultEditorBuilder
All Implemented Interfaces:
BaseBuilder<EditorBuilder>, EditorBuilder

public class DefaultEditorBuilder extends Object implements EditorBuilder
Default implementation of EditorBuilder.
  • Constructor Details

    • DefaultEditorBuilder

      public DefaultEditorBuilder(PromptBuilder parent)
  • Method Details

    • name

      public EditorBuilder name(String name)
      Description copied from interface: BaseBuilder
      Set 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:
      name in interface BaseBuilder<EditorBuilder>
      Parameters:
      name - the unique identifier for this prompt (required, non-null, non-empty)
      Returns:
      this builder instance for method chaining
    • message

      public EditorBuilder message(String message)
      Description copied from interface: BaseBuilder
      Set 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:
      message in interface BaseBuilder<EditorBuilder>
      Parameters:
      message - the message to display to the user (required, non-null, non-empty)
      Returns:
      this builder instance for method chaining
    • initialText

      public EditorBuilder initialText(String initialText)
      Description copied from interface: EditorBuilder
      Set the initial text for the editor.
      Specified by:
      initialText in interface EditorBuilder
      Parameters:
      initialText - the initial text
      Returns:
      this builder
    • fileExtension

      public EditorBuilder fileExtension(String fileExtension)
      Description copied from interface: EditorBuilder
      Set the file extension for syntax highlighting.
      Specified by:
      fileExtension in interface EditorBuilder
      Parameters:
      fileExtension - the file extension (without dot)
      Returns:
      this builder
    • title

      public EditorBuilder title(String title)
      Description copied from interface: EditorBuilder
      Set the title for the editor.
      Specified by:
      title in interface EditorBuilder
      Parameters:
      title - the editor title
      Returns:
      this builder
    • showLineNumbers

      public EditorBuilder showLineNumbers(boolean showLineNumbers)
      Description copied from interface: EditorBuilder
      Set whether to show line numbers.
      Specified by:
      showLineNumbers in interface EditorBuilder
      Parameters:
      showLineNumbers - true to show line numbers
      Returns:
      this builder
    • enableWrapping

      public EditorBuilder enableWrapping(boolean enableWrapping)
      Description copied from interface: EditorBuilder
      Set whether to enable text wrapping.
      Specified by:
      enableWrapping in interface EditorBuilder
      Parameters:
      enableWrapping - true to enable wrapping
      Returns:
      this builder
    • transformer

      public EditorBuilder transformer(Function<String,String> transformer)
      Description copied from interface: BaseBuilder
      Set 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:
      transformer in interface BaseBuilder<EditorBuilder>
      Parameters:
      transformer - the transformer function
      Returns:
      this builder instance for method chaining
    • filter

      public EditorBuilder filter(Function<String,String> filter)
      Description copied from interface: BaseBuilder
      Set 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:
      filter in interface BaseBuilder<EditorBuilder>
      Parameters:
      filter - the filter function
      Returns:
      this builder instance for method chaining
    • addPrompt

      public PromptBuilder addPrompt()
      Description copied from interface: BaseBuilder
      Complete 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 call PromptBuilder.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:
      addPrompt in interface BaseBuilder<EditorBuilder>
      Returns:
      the parent PromptBuilder for continued prompt configuration
      See Also: