# README
go-choice
A very simple library for interactively selecting an option on a terminal
Usage
package main
import (
"fmt"
"github.com/TwiN/go-choice"
)
func main() {
choice, index, err := gochoice.Pick(
"What do you want to do?\nPick:",
[]string{
"Connect to the production environment",
"Connect to the test environment",
"Update",
},
)
if err != nil {
fmt.Println("You didn't select anything!")
} else {
fmt.Printf("You have selected: '%s', which is the index %d\n", choice, index)
}
}
You can customize the experience further by appending options at the end of the Pick
function:
package main
import (
"fmt"
"github.com/TwiN/go-choice"
)
func main() {
choice, index, err := gochoice.Pick(
"What do you want to do?\nPick:",
[]string{
"Connect to the production environment",
"Connect to the test environment",
"Update",
},
gochoice.OptionBackgroundColor(gochoice.Black),
gochoice.OptionTextColor(gochoice.White),
gochoice.OptionSelectedTextColor(gochoice.Red),
gochoice.OptionSelectedTextBold(),
)
if err != nil {
fmt.Println("You didn't select anything!")
} else {
fmt.Printf("You have selected: '%s', which is the index %d\n", choice, index)
}
}
# Functions
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
Pick prompts the user to choose an option from a list of choices.
# Constants
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
# Variables
ErrNoChoice is the error returned when there are no choices to pick from.
ErrNoChoiceSelected is the error returned when no choices have been selected.