Skip to content
/ go-choice Public

A very simple library for interactively selecting an option on a terminal

License

Notifications You must be signed in to change notification settings

TwiN/go-choice

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

65 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

go-choice

test

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)
    }
}

example

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)
    }
}

About

A very simple library for interactively selecting an option on a terminal

Topics

Resources

License

Code of conduct

Stars

Watchers

Forks

Sponsor this project

 

Languages