Package org.jline.consoleui.prompt
Class ConsolePrompt
- java.lang.Object
-
- org.jline.consoleui.prompt.ConsolePrompt
-
public class ConsolePrompt extends java.lang.Object
ConsolePrompt encapsulates the prompting of a list of input questions for the user.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
ConsolePrompt.UiConfig
ConsoleUI configuration: colors, cursor pointer and selected/unselected/unavailable boxes.
-
Field Summary
Fields Modifier and Type Field Description protected org.jline.terminal.Attributes
attributes
protected ConsolePrompt.UiConfig
config
protected org.jline.utils.Display
display
protected java.util.List<org.jline.utils.AttributedString>
header
protected org.jline.reader.LineReader
reader
protected org.jline.terminal.Terminal
terminal
-
Constructor Summary
Constructors Constructor Description ConsolePrompt(org.jline.reader.LineReader reader, org.jline.terminal.Terminal terminal, ConsolePrompt.UiConfig config)
ConsolePrompt(org.jline.terminal.Terminal terminal)
ConsolePrompt(org.jline.terminal.Terminal terminal, ConsolePrompt.UiConfig config)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
close()
static int
computePageSize(org.jline.terminal.Terminal terminal, int pageSize, PageSizeType sizeType)
protected org.jline.utils.AttributedStringBuilder
createMessage(java.lang.String message, java.lang.String response)
PromptBuilder
getPromptBuilder()
Creates aPromptBuilder
.protected void
open()
java.util.Map<java.lang.String,PromptResultItemIF>
prompt(java.util.function.Function<java.util.Map<java.lang.String,PromptResultItemIF>,java.util.List<PromptableElementIF>> promptableElementLists)
Prompt a list of choices (questions).java.util.Map<java.lang.String,PromptResultItemIF>
prompt(java.util.List<PromptableElementIF> promptableElementList)
Prompt a list of choices (questions).java.util.Map<java.lang.String,PromptResultItemIF>
prompt(java.util.List<org.jline.utils.AttributedString> headerIn, java.util.function.Function<java.util.Map<java.lang.String,PromptResultItemIF>,java.util.List<PromptableElementIF>> promptableElementLists)
Prompt a list of choices (questions).java.util.Map<java.lang.String,PromptResultItemIF>
prompt(java.util.List<org.jline.utils.AttributedString> header, java.util.List<PromptableElementIF> promptableElementList)
Prompt a list of choices (questions).protected void
prompt(java.util.List<org.jline.utils.AttributedString> headerIn, java.util.List<PromptableElementIF> promptableElementList, java.util.Map<java.lang.String,PromptResultItemIF> resultMap)
Prompt a list of choices (questions).protected PromptResultItemIF
promptElement(java.util.List<org.jline.utils.AttributedString> header, PromptableElementIF pe, PromptResultItemIF oldResult)
-
-
-
Field Detail
-
reader
protected final org.jline.reader.LineReader reader
-
terminal
protected final org.jline.terminal.Terminal terminal
-
display
protected final org.jline.utils.Display display
-
config
protected final ConsolePrompt.UiConfig config
-
attributes
protected org.jline.terminal.Attributes attributes
-
header
protected java.util.List<org.jline.utils.AttributedString> header
-
-
Constructor Detail
-
ConsolePrompt
public ConsolePrompt(org.jline.terminal.Terminal terminal)
- Parameters:
terminal
- the terminal.
-
ConsolePrompt
public ConsolePrompt(org.jline.terminal.Terminal terminal, ConsolePrompt.UiConfig config)
- Parameters:
terminal
- the terminal.config
- ConsolePrompt cursor pointer and checkbox configuration
-
ConsolePrompt
public ConsolePrompt(org.jline.reader.LineReader reader, org.jline.terminal.Terminal terminal, ConsolePrompt.UiConfig config)
- Parameters:
reader
- the lineReader.terminal
- the terminal.config
- ConsolePrompt cursor pointer and checkbox configuration
-
-
Method Detail
-
open
protected void open()
-
close
protected void close()
-
prompt
public java.util.Map<java.lang.String,PromptResultItemIF> prompt(java.util.List<PromptableElementIF> promptableElementList) throws java.io.IOException, org.jline.reader.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:
java.io.IOException
- may be thrown by terminalorg.jline.reader.UserInterruptException
- if user interrupt handling is enabled and the user types the interrupt character (ctrl-C)
-
prompt
public java.util.Map<java.lang.String,PromptResultItemIF> prompt(java.util.List<org.jline.utils.AttributedString> header, java.util.List<PromptableElementIF> promptableElementList) throws java.io.IOException, org.jline.reader.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:
java.io.IOException
- may be thrown by terminalorg.jline.reader.UserInterruptException
- if user interrupt handling is enabled and the user types the interrupt character (ctrl-C)
-
prompt
public java.util.Map<java.lang.String,PromptResultItemIF> prompt(java.util.function.Function<java.util.Map<java.lang.String,PromptResultItemIF>,java.util.List<PromptableElementIF>> promptableElementLists) throws java.io.IOException
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:
java.io.IOException
- may be thrown by terminal
-
prompt
public java.util.Map<java.lang.String,PromptResultItemIF> prompt(java.util.List<org.jline.utils.AttributedString> headerIn, java.util.function.Function<java.util.Map<java.lang.String,PromptResultItemIF>,java.util.List<PromptableElementIF>> promptableElementLists) throws java.io.IOException
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:
java.io.IOException
- may be thrown by terminal
-
prompt
protected void prompt(java.util.List<org.jline.utils.AttributedString> headerIn, java.util.List<PromptableElementIF> promptableElementList, java.util.Map<java.lang.String,PromptResultItemIF> resultMap) throws java.io.IOException
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:
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:
java.io.IOException
- may be thrown by terminal
-
promptElement
protected PromptResultItemIF promptElement(java.util.List<org.jline.utils.AttributedString> header, PromptableElementIF pe, PromptResultItemIF oldResult)
-
createMessage
protected org.jline.utils.AttributedStringBuilder createMessage(java.lang.String message, java.lang.String response)
-
computePageSize
public static int computePageSize(org.jline.terminal.Terminal terminal, int pageSize, PageSizeType sizeType)
-
getPromptBuilder
public PromptBuilder getPromptBuilder()
Creates aPromptBuilder
.- Returns:
- a new prompt builder object.
-
-