Class Prompt<TOption>
- java.lang.Object
-
- com.github.rvesse.airline.prompts.Prompt<TOption>
-
- Type Parameters:
TOption- Option type
public class Prompt<TOption> extends java.lang.ObjectRepresents a prompt
-
-
Field Summary
Fields Modifier and Type Field Description private booleanallowNumericOptionSelectionprivate TypeConverterconverterprivate java.util.concurrent.ExecutorServiceexecutorprivate PromptFormatterformatterprivate java.lang.Stringmessageprivate PromptOptionMatcher<TOption>optionMatcherprivate java.util.List<TOption>optionsprivate PromptProviderproviderprivate longtimeoutprivate java.util.concurrent.TimeUnittimeoutUnit
-
Constructor Summary
Constructors Constructor Description 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
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanallowsNumericOptionSelection()Gets whether options can be selected numerically when usingpromptForOption(boolean)private voiddisplayPrompt()Displays the promptjava.lang.StringgetMessage()Gets the prompt messagePromptOptionMatcher<TOption>getOptionMatcher()java.util.List<TOption>getOptions()Gets the available options (if any)PromptProvidergetProvider()Gets the prompt providerlonggetTimeout()Gets the configured timeoutjava.util.concurrent.TimeUnitgetTimeoutUnit()Gets the timeout unitTypeConvertergetTypeConverter()Gets the configured type converterintpromptForKey()Prompts for a single keyjava.lang.StringpromptForLine()Prompts for a line of inputTOptionpromptForOption(boolean secure)Prompts for optionchar[]promptForSecure()Prompts for a secure input line<T> TpromptForValue(java.lang.Class<T> cls, boolean secure)Prompts for a valueprotected <T> TwaitForPromptResponse(java.util.concurrent.Future<T> future)Wait for a prompt response
-
-
-
Field Detail
-
provider
private final PromptProvider provider
-
formatter
private final PromptFormatter formatter
-
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
-
optionMatcher
private final PromptOptionMatcher<TOption> optionMatcher
-
message
private final java.lang.String message
-
converter
private final TypeConverter converter
-
-
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 Providerformatter- Prompt Formattertimeout- TimeouttimeoutUnit- Timeout UnitpromptMessage- Prompt Messageoptions- OptionsoptionMatcher- Option matcherallowNumericOptionSelection- Whether numeric option selection is allowedconverter- 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 usingpromptForOption(boolean)- Returns:
- True if numeric selection enabled, false otherwise
-
getOptions
public java.util.List<TOption> getOptions()
Gets the available options (if any)- Returns:
- Options
-
getOptionMatcher
public PromptOptionMatcher<TOption> getOptionMatcher()
-
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 PromptExceptionWait for a prompt response- Type Parameters:
T- Response type- Parameters:
future- Future- Returns:
- Response type
- Throws:
PromptException
-
promptForKey
public int promptForKey() throws PromptExceptionPrompts for a single key- Returns:
- Key code
- Throws:
PromptException
-
promptForLine
public java.lang.String promptForLine() throws PromptExceptionPrompts 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 PromptExceptionPrompts for a value- Type Parameters:
T- Value type- Parameters:
cls- Value type classsecure- Does the response need to be secure?- Returns:
- Value
- Throws:
PromptException
-
promptForSecure
public char[] promptForSecure() throws PromptExceptionPrompts for a secure input line- Returns:
- Input line
- Throws:
PromptException- Thrown if the underlying prompt provider does not support secure reads
-
-