Class Dialog

java.lang.Object
io.xpipe.core.dialog.Dialog
Direct Known Subclasses:
Dialog.Choice, Dialog.Query

public abstract class Dialog extends Object
A Dialog is a sequence of questions and answers.

The dialogue API is only used for the command line interface. Therefore, the actual implementation is handled by the command line component. This API provides a way of creating server-side dialogues which makes it possible to create extensions that provide a commandline configuration component.

When a Dialog is completed, it can also be optionally evaluated to a value, which can be queried by calling getResult(). The evaluation function can be set with evaluateTo(Supplier). Alternatively, a dialogue can also copy the evaluation function of another dialogue with evaluateTo(Dialog). An evaluation result can also be mapped to another type with map(Function). It is also possible to listen for the completion of this dialogue with onCompletion(Charsetter.FailableConsumer) )}.

  • Field Details

    • eval

      protected Object eval
  • Constructor Details

    • Dialog

      public Dialog()
  • Method Details

    • empty

      public static Dialog empty()
      Creates an empty dialogue. This dialogue completes immediately and does not handle any questions or answers.
    • choice

      public static Dialog.Choice choice(String description, List<Choice> elements, boolean required, boolean quiet, int selected)
      Creates a choice dialogue.
      Parameters:
      description - the shown question description
      elements - the available elements to choose from
      required - signals whether a choice is required or can be left empty
      selected - the selected element index
    • choice

      @SafeVarargs public static <T> Dialog.Choice choice(String description, Function<T,String> toString, boolean required, boolean quiet, T def, T... vals)
      Creates a choice dialogue from a set of objects.
      Parameters:
      description - the shown question description
      toString - a function that maps the objects to a string
      required - signals whether choices required or can be left empty
      quiet -
      def - the element which is selected by default
      vals - the range of possible elements
    • query

      public static <T> Dialog.Query query(String description, boolean newLine, boolean required, boolean quiet, T value, QueryConverter<T> converter)
      Creates a simple query dialogue.
      Parameters:
      description - the shown question description
      newLine - signals whether the query should be done on a new line or not
      required - signals whether the query can be left empty or not
      quiet - signals whether the user should be explicitly queried for the value. In case the user is not queried, a value can still be set using the command line arguments that allow to set the specific value for a configuration query parameter
      value - the default value
      converter - the converter
    • querySecret

      public static Dialog.Query querySecret(String description, boolean newLine, boolean required, SecretValue value)
    • chain

      public static Dialog chain(Dialog... ds)
      Chains multiple dialogues together.
      Parameters:
      ds - the dialogues
    • repeatIf

      public static <T> Dialog repeatIf(Dialog d, Predicate<T> shouldRepeat)
      Creates a dialogue that starts from the beginning if the repeating condition is true.
    • header

      public static Dialog header(String msg)
      Create a simple dialogue that will print a message.
    • header

      public static Dialog header(Supplier<String> msg)
      Create a simple dialogue that will print a message.
    • busy

      public static Dialog busy()
      Creates a dialogue that will show a loading icon until the next dialogue question is sent.
    • lazy

      public static Dialog lazy(FailableSupplier<Dialog> d)
      Creates a dialogue that will only evaluate when needed. This allows a dialogue to incorporate completion information about a previous dialogue.
    • skipIf

      public static Dialog skipIf(Dialog d, Supplier<Boolean> check)
      Creates a dialogue that will not be executed if the condition is true.
    • retryIf

      public static <T> Dialog retryIf(Dialog d, Function<T,String> msg)
      Creates a dialogue that will repeat with an error message if the condition is met.
    • fork

      public static Dialog fork(String description, List<Choice> elements, boolean required, int selected, Function<Integer,Dialog> c)
      Creates a dialogue that will fork the control flow.
      Parameters:
      description - the shown question description
      elements - the available elements to choose from
      required - signals whether a choice is required or not
      selected - the index of the element that is selected by default
      c - the dialogue index mapping function
    • clearCompletion

      public void clearCompletion()
      Removes all completion listeners. Intended for internal use only.
    • start

      public abstract DialogElement start() throws Exception
      Throws:
      Exception
    • evaluateTo

      public Dialog evaluateTo(Dialog d)
    • evaluateTo

      public Dialog evaluateTo(Supplier<?> s)
    • map

      public <T> Dialog map(Function<T,?> s)
    • onCompletion

      public Dialog onCompletion(FailableConsumer<?,Exception> s)
    • onCompletion

      public Dialog onCompletion(Runnable r)
    • onCompletion

      public Dialog onCompletion(List<FailableConsumer<?,Exception>> s)
    • getResult

      public <T> T getResult()
    • complete

      public <T> void complete() throws Exception
      Throws:
      Exception
    • receive

      public final DialogElement receive(String answer) throws Exception
      Throws:
      Exception
    • next

      protected abstract DialogElement next(String answer) throws Exception
      Throws:
      Exception