Class Prompt<TOption>

  • Type Parameters:
    TOption - Option type

    public class Prompt<TOption>
    extends java.lang.Object
    Represents a prompt
    • Field Detail

      • timeout

        private final long timeout
      • allowNumericOptionSelection

        private final boolean allowNumericOptionSelection
      • timeoutUnit

        private final java.util.concurrent.TimeUnit timeoutUnit
      • executor

        private final java.util.concurrent.ExecutorService executor
      • options

        private final java.util.List<TOption> options
      • message

        private final java.lang.String message
    • Constructor Detail

      • Prompt

        public Prompt​(PromptProvider provider,
                      PromptFormatter formatter,
                      long timeout,
                      java.util.concurrent.TimeUnit timeoutUnit,
                      java.lang.String promptMessage,
                      java.util.Collection<TOption> options,
                      PromptOptionMatcher<TOption> optionMatcher,
                      boolean allowNumericOptionSelection,
                      TypeConverter converter)
        Creates a new prompt
        Parameters:
        provider - Prompt Provider
        formatter - Prompt Formatter
        timeout - Timeout
        timeoutUnit - Timeout Unit
        promptMessage - Prompt Message
        options - Options
        optionMatcher - Option matcher
        allowNumericOptionSelection - Whether numeric option selection is allowed
        converter - Type converter
    • Method Detail

      • getProvider

        public PromptProvider getProvider()
        Gets the prompt provider
        Returns:
        Provider
      • getMessage

        public java.lang.String getMessage()
        Gets the prompt message
        Returns:
        Message
      • allowsNumericOptionSelection

        public boolean allowsNumericOptionSelection()
        Gets whether options can be selected numerically when using promptForOption(boolean)
        Returns:
        True if numeric selection enabled, false otherwise
      • getOptions

        public java.util.List<TOption> getOptions()
        Gets the available options (if any)
        Returns:
        Options
      • getTypeConverter

        public TypeConverter getTypeConverter()
        Gets the configured type converter
        Returns:
        Type converter
      • getTimeout

        public long getTimeout()
        Gets the configured timeout
        Returns:
        Configured timeout or 0 if no timeout
      • getTimeoutUnit

        public java.util.concurrent.TimeUnit getTimeoutUnit()
        Gets the timeout unit
        Returns:
        Timeout unit
      • displayPrompt

        private void displayPrompt()
        Displays the prompt
      • waitForPromptResponse

        protected <T> T waitForPromptResponse​(java.util.concurrent.Future<T> future)
                                       throws PromptException
        Wait for a prompt response
        Type Parameters:
        T - Response type
        Parameters:
        future - Future
        Returns:
        Response type
        Throws:
        PromptException
      • promptForLine

        public java.lang.String promptForLine()
                                       throws PromptException
        Prompts for a line of input
        Returns:
        Input line
        Throws:
        PromptException
      • promptForOption

        public TOption promptForOption​(boolean secure)
                                throws PromptException
        Prompts for option
        Parameters:
        secure - Does the response need to be secure?
        Returns:
        Option value
        Throws:
        PromptException
      • promptForValue

        public <T> T promptForValue​(java.lang.Class<T> cls,
                                    boolean secure)
                             throws PromptException
        Prompts for a value
        Type Parameters:
        T - Value type
        Parameters:
        cls - Value type class
        secure - Does the response need to be secure?
        Returns:
        Value
        Throws:
        PromptException
      • promptForSecure

        public char[] promptForSecure()
                               throws PromptException
        Prompts for a secure input line
        Returns:
        Input line
        Throws:
        PromptException - Thrown if the underlying prompt provider does not support secure reads