Package org.jline.consoleui.prompt
Class ConsolePrompt
java.lang.Object
org.jline.consoleui.prompt.ConsolePrompt
ConsolePrompt encapsulates the prompting of a list of input questions for the user.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
ConsoleUI configuration: colors, cursor pointer and selected/unselected/unavailable boxes. -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected Attributes
protected final ConsolePrompt.UiConfig
protected List
<AttributedString> protected final LineReader
protected final Terminal
-
Constructor Summary
ConstructorsConstructorDescriptionConsolePrompt
(LineReader reader, Terminal terminal, ConsolePrompt.UiConfig config) ConsolePrompt
(Terminal terminal) ConsolePrompt
(Terminal terminal, ConsolePrompt.UiConfig config) -
Method Summary
Modifier and TypeMethodDescriptionprotected void
close()
static int
computePageSize
(Terminal terminal, int pageSize, PageSizeType sizeType) protected AttributedStringBuilder
createMessage
(String message, String response) Creates aPromptBuilder
.protected void
open()
prompt
(Function<Map<String, PromptResultItemIF>, List<PromptableElementIF>> promptableElementLists) Prompt a list of choices (questions).prompt
(List<PromptableElementIF> promptableElementList) Prompt a list of choices (questions).prompt
(List<AttributedString> headerIn, Function<Map<String, PromptResultItemIF>, List<PromptableElementIF>> promptableElementLists) Prompt a list of choices (questions).prompt
(List<AttributedString> header, List<PromptableElementIF> promptableElementList) Prompt a list of choices (questions).protected void
prompt
(List<AttributedString> headerIn, List<PromptableElementIF> promptableElementList, Map<String, PromptResultItemIF> resultMap) Prompt a list of choices (questions).protected PromptResultItemIF
promptElement
(List<AttributedString> header, PromptableElementIF pe, PromptResultItemIF oldResult) private Map
<String, PromptResultItemIF> removeNoResults
(Map<String, PromptResultItemIF> resultMap) private void
private boolean
-
Field Details
-
reader
-
terminal
-
config
-
attributes
-
header
-
-
Constructor Details
-
ConsolePrompt
- Parameters:
terminal
- the terminal.
-
ConsolePrompt
- Parameters:
terminal
- the terminal.config
- ConsolePrompt cursor pointer and checkbox configuration
-
ConsolePrompt
- Parameters:
reader
- the lineReader.terminal
- the terminal.config
- ConsolePrompt cursor pointer and checkbox configuration
-
-
Method Details
-
open
protected void open() -
close
protected void close() -
terminalInRawMode
private boolean terminalInRawMode() -
prompt
public Map<String,PromptResultItemIF> prompt(List<PromptableElementIF> promptableElementList) throws IOException, UserInterruptException Prompt a list of choices (questions). This method takes a list of promptable elements, typically created withPromptBuilder
. Each of the elements is processed and the user entries and answers are filled in to the result map. The result map contains the key of each promptable element and the user entry as an object implementingPromptResultItemIF
.- Parameters:
promptableElementList
- the list of questions / prompts to ask the user for.- Returns:
- a map containing a result for each element of promptableElementList
- Throws:
IOException
- may be thrown by terminalUserInterruptException
- if user interrupt handling is enabled and the user types the interrupt character (ctrl-C)
-
prompt
public Map<String,PromptResultItemIF> prompt(List<AttributedString> header, List<PromptableElementIF> promptableElementList) throws IOException, UserInterruptException Prompt a list of choices (questions). This method takes a list of promptable elements, typically created withPromptBuilder
. Each of the elements is processed and the user entries and answers are filled in to the result map. The result map contains the key of each promptable element and the user entry as an object implementingPromptResultItemIF
.- Parameters:
header
- info to be displayed before first prompt.promptableElementList
- the list of questions / prompts to ask the user for.- Returns:
- a map containing a result for each element of promptableElementList
- Throws:
IOException
- may be thrown by terminalUserInterruptException
- if user interrupt handling is enabled and the user types the interrupt character (ctrl-C)
-
prompt
public Map<String,PromptResultItemIF> prompt(Function<Map<String, PromptResultItemIF>, throws IOExceptionList<PromptableElementIF>> promptableElementLists) Prompt a list of choices (questions). This method takes a function that given a map of interim results returns a list of promptable elements (typically created withPromptBuilder
). Each list is then passed toprompt(List, List, Map)
and the result added to the map of interim results. The function is then called again with the updated map of results until the function returns null. The final result map contains the key of each promptable element and the user entry as an object implementingPromptResultItemIF
.- Parameters:
promptableElementLists
- a function returning lists of questions / prompts to ask the user for.- Throws:
IOException
- may be thrown by terminal
-
prompt
public Map<String,PromptResultItemIF> prompt(List<AttributedString> headerIn, Function<Map<String, PromptResultItemIF>, throws IOExceptionList<PromptableElementIF>> promptableElementLists) Prompt a list of choices (questions). This method takes a function that given a map of interim results returns a list of promptable elements (typically created withPromptBuilder
). Each list is then passed toprompt(List, List, Map)
and the result added to the map of interim results. The function is then called again with the updated map of results until the function returns null. The final result map contains the key of each promptable element and the user entry as an object implementingPromptResultItemIF
.- Parameters:
headerIn
- info to be displayed before first prompt.promptableElementLists
- a function returning lists of questions / prompts to ask the user for.- Throws:
IOException
- may be thrown by terminal
-
prompt
protected void prompt(List<AttributedString> headerIn, List<PromptableElementIF> promptableElementList, Map<String, PromptResultItemIF> resultMap) throws IOExceptionPrompt a list of choices (questions). This method takes a list of promptable elements, typically created withPromptBuilder
. Each of the elements is processed and the user entries and answers are filled in to the result map. The result map contains the key of each promptable element and the user entry as an object implementingPromptResultItemIF
.- Parameters:
headerIn
- info to be displayed before first prompt.promptableElementList
- the list of questions / prompts to ask the user for.resultMap
- a map containing a result for each element of promptableElementList- Throws:
IOException
- may be thrown by terminal
-
promptElement
protected PromptResultItemIF promptElement(List<AttributedString> header, PromptableElementIF pe, PromptResultItemIF oldResult) -
createMessage
-
computePageSize
-
removePreviousResult
-
removeNoResults
-
getPromptBuilder
Creates aPromptBuilder
.- Returns:
- a new prompt builder object.
-