interakt
Interactive prompts made easy!
Install
Gradle - Kotlin DSL
repositories {
mavenCentral()
}
dependencies {
implementation("xyz.davidsimon:interakt:0.1.0")
}
Maven
<dependency>
<groupId>xyz.davidsimongroupId>
<artifactId>interaktartifactId>
<version>0.1.0version>
dependency>
Usage
To construct and run an interactive prompt, you need to:
- Obtain a
Prompt
instance - Add
PromptField
s to the prompt - Execute the prompt
Using a few convenience methods, we can achieve all this in just a few lines of code:
prompt {
text("foo:", default = "default value")
integer("bar:", default = 42)
list("baz:", listOf("1", "2", "3"), true)
println("Result:")
for((key, value) in execute()) {
println("${key.promptMessage} $value")
}
}
Fields
PromptField
Base class for all other fields
Options:
Parameter | Type | Description |
---|---|---|
promptMessage | String |
Message to display before user input |
shouldPrompt | (PromptResult, PromptField
|
Controls whether the field should be prompted. Receives the answers entered so far and the current field's instance |
default | (PromptResult, PromptField
|
Provides a default value that will be pre-filled |
TextField
Prompts user for simple text input
IntegerField
Prompts user for integer input
ListField
Prompts the user to choose from a list of items. The displayed name and the actual value of the items may differ.
Options:
Parameter | Type | Description |
---|---|---|
choices | (PromptResult) -> List
|
Returns the available choices |
TextListField
Prompts the user to choose from a list of text items. Optionally the user may enter a custom value.
Options:
Parameter | Type | Description |
---|---|---|
choices | (tr: PromptResult) -> List
|
Returns the available choices |
allowCustom | Boolean |
Allow the user to enter a custom value. If true an additional choice will be added with an empty string value |
customPromptMessage | String |
Message to display when user enter custom value |
Acknowledgement
interakt is built using JLine