Class InteractivePrompt

java.lang.Object
cloud.kitelang.cli.interactive.InteractivePrompt
All Implemented Interfaces:
AutoCloseable

public class InteractivePrompt extends Object implements AutoCloseable
Wrapper around JLine ConsoleUI for interactive terminal prompts. Provides single-select, multi-select, confirmation, and text input capabilities.
  • Method Details

    • create

      public static InteractivePrompt create()
      Creates an InteractivePrompt instance using the shared Console terminal. Returns null if terminal is not available (e.g., piped input).
    • isInteractive

      public static boolean isInteractive()
      Checks if the terminal supports interactive mode.
    • selectOne

      public String selectOne(String message, List<InteractivePrompt.Option> options) throws IOException
      Displays a single-select list prompt with arrow key navigation.
      Parameters:
      message - The prompt message
      options - The list of options to choose from
      Returns:
      The selected option's ID, or null if cancelled
      Throws:
      IOException
    • selectMany

      public List<String> selectMany(String message, List<InteractivePrompt.Option> options) throws IOException
      Displays a multi-select checkbox prompt.
      Parameters:
      message - The prompt message
      options - The list of options to choose from
      Returns:
      List of selected option IDs
      Throws:
      IOException
    • confirm

      public boolean confirm(String message, boolean defaultValue) throws IOException
      Displays a Yes/No confirmation prompt.
      Parameters:
      message - The confirmation message
      defaultValue - The default value if user just presses Enter
      Returns:
      true for Yes, false for No
      Throws:
      IOException
    • input

      public String input(String message, String defaultValue) throws IOException
      Displays a text input prompt.
      Parameters:
      message - The prompt message
      defaultValue - The default value (shown in brackets)
      Returns:
      The user's input, or the default value if empty
      Throws:
      IOException
    • password

      public String password(String message) throws IOException
      Displays a password input prompt (input is masked).
      Parameters:
      message - The prompt message
      Returns:
      The entered password
      Throws:
      IOException
    • printHeader

      public void printHeader(String title)
      Prints a styled header.
    • printSuccess

      public void printSuccess(String message)
      Prints a success message with green checkmark.
    • printError

      public void printError(String message)
      Prints an error message with red X mark.
    • printWarning

      public void printWarning(String message)
      Prints a warning message with yellow indicator.
    • printInfo

      public void printInfo(String message)
      Prints an info message.
    • printSeparator

      public void printSeparator()
      Prints a separator line to visually separate sections and reset cursor.
    • printPrompt

      public void printPrompt(String message)
      Prints a prompt/question indicator (cyan ?).
    • close

      public void close()
      Specified by:
      close in interface AutoCloseable