Class InteractivePrompt
java.lang.Object
cloud.kitelang.cli.interactive.InteractivePrompt
- All Implemented Interfaces:
AutoCloseable
Wrapper around JLine ConsoleUI for interactive terminal prompts.
Provides single-select, multi-select, confirmation, and text input capabilities.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final recordRepresents an option in a selection prompt. -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()booleanDisplays a Yes/No confirmation prompt.static InteractivePromptcreate()Creates an InteractivePrompt instance using the shared Console terminal.Displays a text input prompt.static booleanChecks if the terminal supports interactive mode.Displays a password input prompt (input is masked).voidprintError(String message) Prints an error message with red X mark.voidprintHeader(String title) Prints a styled header.voidPrints an info message.voidprintPrompt(String message) Prints a prompt/question indicator (cyan ?).voidPrints a separator line to visually separate sections and reset cursor.voidprintSuccess(String message) Prints a success message with green checkmark.voidprintWarning(String message) Prints a warning message with yellow indicator.selectMany(String message, List<InteractivePrompt.Option> options) Displays a multi-select checkbox prompt.selectOne(String message, List<InteractivePrompt.Option> options) Displays a single-select list prompt with arrow key navigation.
-
Method Details
-
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
Displays a single-select list prompt with arrow key navigation.- Parameters:
message- The prompt messageoptions- 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 messageoptions- The list of options to choose from- Returns:
- List of selected option IDs
- Throws:
IOException
-
confirm
Displays a Yes/No confirmation prompt.- Parameters:
message- The confirmation messagedefaultValue- The default value if user just presses Enter- Returns:
- true for Yes, false for No
- Throws:
IOException
-
input
Displays a text input prompt.- Parameters:
message- The prompt messagedefaultValue- The default value (shown in brackets)- Returns:
- The user's input, or the default value if empty
- Throws:
IOException
-
password
Displays a password input prompt (input is masked).- Parameters:
message- The prompt message- Returns:
- The entered password
- Throws:
IOException
-
printHeader
Prints a styled header. -
printSuccess
Prints a success message with green checkmark. -
printError
Prints an error message with red X mark. -
printWarning
Prints a warning message with yellow indicator. -
printInfo
Prints an info message. -
printSeparator
public void printSeparator()Prints a separator line to visually separate sections and reset cursor. -
printPrompt
Prints a prompt/question indicator (cyan ?). -
close
public void close()- Specified by:
closein interfaceAutoCloseable
-