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.Object
Represents a prompt
-
-
Field Summary
Fields Modifier and Type Field Description private boolean
allowNumericOptionSelection
private TypeConverter
converter
private java.util.concurrent.ExecutorService
executor
private PromptFormatter
formatter
private java.lang.String
message
private PromptOptionMatcher<TOption>
optionMatcher
private java.util.List<TOption>
options
private PromptProvider
provider
private long
timeout
private java.util.concurrent.TimeUnit
timeoutUnit
-
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 boolean
allowsNumericOptionSelection()
Gets whether options can be selected numerically when usingpromptForOption(boolean)
private void
displayPrompt()
Displays the promptjava.lang.String
getMessage()
Gets the prompt messagePromptOptionMatcher<TOption>
getOptionMatcher()
java.util.List<TOption>
getOptions()
Gets the available options (if any)PromptProvider
getProvider()
Gets the prompt providerlong
getTimeout()
Gets the configured timeoutjava.util.concurrent.TimeUnit
getTimeoutUnit()
Gets the timeout unitTypeConverter
getTypeConverter()
Gets the configured type converterint
promptForKey()
Prompts for a single keyjava.lang.String
promptForLine()
Prompts for a line of inputTOption
promptForOption(boolean secure)
Prompts for optionchar[]
promptForSecure()
Prompts for a secure input line<T> T
promptForValue(java.lang.Class<T> cls, boolean secure)
Prompts for a valueprotected <T> T
waitForPromptResponse(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 PromptException
Wait for a prompt response- Type Parameters:
T
- Response type- Parameters:
future
- Future- Returns:
- Response type
- Throws:
PromptException
-
promptForKey
public int promptForKey() throws PromptException
Prompts for a single key- Returns:
- Key code
- 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 classsecure
- 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
-
-