Another GoLang prompt library with a couple of uncommon features:
- Supports more advanced text editing by using my Go Text Editor library
- Multiline text editing
- Better cursor movement (
up,down,home, andendall work)
- Doesn't clear out and of your screen
- Yes/No questions with
Boolean{<options>} - Select from list with
Select{<options>} - Text (multiline and single line) with
Text{<options>}
All prompts are created by initializing their respective struct.
input := prompt.Text{}The zero value of the prompt is ready to use, but you will probably want to explore the available public members to customize the prompt.
input := prompt.Text{
Question: "What is your name?",
IsSingleLine: true,
ValidatorFunc: func(input []string) string {
if input[0] == "" {
return "name is required"
}
return ""
},
}When the prompt is ready, call Show to display the prompt and block the active Go-Routine until a response is submitted. Then call Response to get the output of the prompt.
err := input.Show()
if err != nil {
// Handle error
}
name := input.Response()
fmt.Printf("Hello %s!", name)