Skip to content

Lightweight menu selection library for CLI choices

License

Notifications You must be signed in to change notification settings

LJ-Rawnet/gocliselect

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Golang CLI Select

Lightweight interactive CLI selection library

Import the package

import "github.com/nexidian/gocliselect"

Usage

Create a new menu, supplying the question as a parameter

menu := gocliselect.NewMenu("Chose a colour")

Add any number of options by calling AddItem() supplying the display text of the option as well as the id

menu.AddItem("Red", "red")
menu.AddItem("Blue", "blue")
menu.AddItem("Green", "green")
menu.AddItem("Yellow", "yellow")
menu.AddItem("Cyan", "cyan")

To display the menu and away the user choice call Display()

choice := menu.Display()

Example

package main

import (
    "fmt"
    "github.com/nexidian/gocliselect"
)

func main() {
    menu := gocliselect.NewMenu("Chose a colour")

    menu.AddItem("Red", "red")
    menu.AddItem("Blue", "blue")
    menu.AddItem("Green", "green")
    menu.AddItem("Yellow", "yellow")
    menu.AddItem("Cyan", "cyan")

    choice := menu.Display()

    fmt.Printf("Choice: %s\n", choice)
}

About

Lightweight menu selection library for CLI choices

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Go 100.0%