Class CliPrompter
High-level routines for interacting with the user to guide them through the wizard-answering process
-
Nested Class Summary
-
Field Summary
Modifier and TypeFieldDescriptionstatic final int
Account for the '1: ' bit that gets added to the first line of every CLI choice.static final int
80 chars is a bit boxy, but using the full terminal is too wide on linuxstatic final int
Try to be a little consistent with indenting menu items, where possible. -
Constructor Summary
ConstructorDescriptionCliPrompter
(nz.org.riskscape.cli.Terminal terminal, List<Asker> askers, Asker defaultAsker, nz.org.riskscape.engine.i18n.Messages messages, nz.org.riskscape.engine.i18n.TranslationContext context) -
Method Summary
Modifier and TypeMethodDescriptionnz.org.riskscape.problem.ResultOrProblems<Object>
ask
(nz.org.riskscape.wizard.bld.IncrementalBuildState buildState, nz.org.riskscape.wizard.Question chosen) Asks the user a Question and gets a single unbound response (which may or may not be valid).boolean
Asks the user a yes/no questionaskWithRepeat
(nz.org.riskscape.wizard.bld.IncrementalBuildState buildState, nz.org.riskscape.wizard.Question chosen) Repeatedly asks the given question until we get a valid response back<T> Choice<T>
<T> T
<T> T
choose
(String prompt, List<T> choiceObjects, Function<T, String> labelFunc, Function<Choice<T>, Choice<T>> modifier) Get the user to choose one of the given items<T> Choice<T>
Ask the user to choose from the given list of choices, returning the thing that was chosen<T> Optional<T>
chooseOptional
(String prompt, String cancelLabel, List<T> choiceObjects, Function<T, String> labelFunc, Function<Choice<T>, Choice<T>> modifier) Get the user to choose one of the given items, also providing a cancel optionvoid
displayProblems
(String header, List<nz.org.riskscape.problem.Problem> problemList) void
displayProblems
(String header, nz.org.riskscape.problem.Problem... problems) nz.org.riskscape.engine.i18n.Messages
nz.org.riskscape.cli.AnsiPrintStream
getOut()
nz.org.riskscape.picocli.CommandLine.Help.Ansi.Text
getPrompt
(nz.org.riskscape.wizard.Question question) Returns formatted Text containing a question.nz.org.riskscape.cli.Terminal
void
printBreadcrumb
(nz.org.riskscape.wizard.survey2.QuestionTree tree, nz.org.riskscape.wizard.Question chosen) Prints out a breadcrumb line to the terminal to display the "parentage" for the given chosen question.void
printError
(String message) nz.org.riskscape.cli.AnsiPrintStream
Shortcut to getOut().println(message)nz.org.riskscape.cli.AnsiPrintStream
printlnTitle
(String prompt) Print a title out to the terminalreadline()
readlineWithTitle
(String title) readlineWithTitle
(nz.org.riskscape.picocli.CommandLine.Help.Ansi.Text title) void
showSuccessMessage
(String successMessage) nz.org.riskscape.picocli.CommandLine.Help.Ansi.Text
-
Field Details
-
DEFAULT_DISPLAY_WIDTH
public static final int DEFAULT_DISPLAY_WIDTH80 chars is a bit boxy, but using the full terminal is too wide on linux
- See Also:
-
DEFAULT_INDENT_WIDTH
public static final int DEFAULT_INDENT_WIDTHTry to be a little consistent with indenting menu items, where possible. But not too much indent or it looks weird.
- See Also:
-
CHOICE_INDENT_WIDTH
public static final int CHOICE_INDENT_WIDTHAccount for the '1: ' bit that gets added to the first line of every CLI choice. (It assumes single-digit choices, so not perfect alignment)
- See Also:
-
YES_NO_CHOICES
-
-
Constructor Details
-
CliPrompter
-
-
Method Details
-
println
Shortcut to getOut().println(message)
-
askIf
Asks the user a yes/no question
-
choose
public <T> T choose(String prompt, List<T> choiceObjects, Function<T, String> labelFunc, Function<Choice<T>, Choice<T>> modifier) Get the user to choose one of the given items
- Parameters:
prompt
- an unformatted title to show the userchoiceObjects
- the list of java objects to choice fromlabelFunc
- a function for generating a label from each itemmodifier
- a function that can arbitrarily change a choice, e.g add a subtitle or a mnemonic- Returns:
- the chosen thing
-
choose
-
chooseOptional
public <T> Optional<T> chooseOptional(String prompt, String cancelLabel, List<T> choiceObjects, Function<T, String> labelFunc, Function<Choice<T>, Choice<T>> modifier) Get the user to choose one of the given items, also providing a cancel option
- Parameters:
prompt
- an unformatted title to show the usercancelLabel
- for a cancel option - the first letter becomes its shortcutchoiceObjects
- the list of java objects to choice fromlabelFunc
- a function for generating a label from each itemmodifier
- a function that can arbitrarily change a choice, e.g add a subtitle or a mnemonic- Returns:
- the chosen thing, or
Optional.empty()
if the cancel choice was given
-
ask
public nz.org.riskscape.problem.ResultOrProblems<Object> ask(nz.org.riskscape.wizard.bld.IncrementalBuildState buildState, nz.org.riskscape.wizard.Question chosen) Asks the user a Question and gets a single unbound response (which may or may not be valid).
-
choose
-
getPrompt
public nz.org.riskscape.picocli.CommandLine.Help.Ansi.Text getPrompt(nz.org.riskscape.wizard.Question question) Returns formatted Text containing a question.
-
choose
public <T> Choice<T> choose(nz.org.riskscape.picocli.CommandLine.Help.Ansi.Text prompt, List<Choice<T>> choices) Ask the user to choose from the given list of choices, returning the thing that was chosen
-
readlineWithTitle
-
readlineWithTitle
-
readline
-
title
-
printlnTitle
Print a title out to the terminal
- Parameters:
prompt
- unformatted, unmarked text to display
-
askWithRepeat
public Object askWithRepeat(nz.org.riskscape.wizard.bld.IncrementalBuildState buildState, nz.org.riskscape.wizard.Question chosen) Repeatedly asks the given question until we get a valid response back
-
displayProblems
-
displayProblems
-
showSuccessMessage
-
printError
-
getLocale
-
printBreadcrumb
public void printBreadcrumb(nz.org.riskscape.wizard.survey2.QuestionTree tree, nz.org.riskscape.wizard.Question chosen) Prints out a breadcrumb line to the terminal to display the "parentage" for the given chosen question. TODO needs to do a better job than just printing out names/ids
-
getTerminal
public nz.org.riskscape.cli.Terminal getTerminal() -
getMessages
public nz.org.riskscape.engine.i18n.Messages getMessages() -
getOut
public nz.org.riskscape.cli.AnsiPrintStream getOut()
-