Class CliPrompter

java.lang.Object
nz.org.riskscape.wizard.CliPrompter

public class CliPrompter extends Object

High-level routines for interacting with the user to guide them through the wizard-answering process

  • Field Details

    • DEFAULT_DISPLAY_WIDTH

      public static final int DEFAULT_DISPLAY_WIDTH

      80 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_WIDTH

      Try 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_WIDTH

      Account 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

      public static final List<Choice<Boolean>> YES_NO_CHOICES
  • Constructor Details

    • CliPrompter

      public CliPrompter(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 Details

    • println

      public nz.org.riskscape.cli.AnsiPrintStream println(Object message)

      Shortcut to getOut().println(message)

    • askIf

      public boolean askIf(String question)

      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 user
      choiceObjects - the list of java objects to choice from
      labelFunc - a function for generating a label from each item
      modifier - a function that can arbitrarily change a choice, e.g add a subtitle or a mnemonic
      Returns:
      the chosen thing
    • choose

      public <T> T choose(String prompt, List<T> choiceObjects, Function<T,String> labelFunc)
    • 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 user
      cancelLabel - for a cancel option - the first letter becomes its shortcut
      choiceObjects - the list of java objects to choice from
      labelFunc - a function for generating a label from each item
      modifier - 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

      public <T> Choice<T> choose(String prompt, List<Choice<T>> choices)
    • 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

      public String readlineWithTitle(String title)
    • readlineWithTitle

      public String readlineWithTitle(nz.org.riskscape.picocli.CommandLine.Help.Ansi.Text title)
    • readline

      public String readline()
    • title

      public nz.org.riskscape.picocli.CommandLine.Help.Ansi.Text title(String prompt)
    • printlnTitle

      public nz.org.riskscape.cli.AnsiPrintStream printlnTitle(String prompt)

      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

      public void displayProblems(String header, nz.org.riskscape.problem.Problem... problems)
    • displayProblems

      public void displayProblems(String header, List<nz.org.riskscape.problem.Problem> problemList)
    • showSuccessMessage

      public void showSuccessMessage(String successMessage)
    • printError

      public void printError(String message)
    • getLocale

      public Locale 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()