Skip to content
munisystemPublic

About

An elegant list item selector for command line interface in Go

Resources

Stars

2 stars

Watchers

0 watching

Forks

Latest commit

 

History

13 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Selector MIT License

Interactive command line user interfaces like Inquirer.js

Installation

$ go get -u github.com/munisystem/selector

Examples

See example/ folder

$ go run example/list.go
$ go run example/checkbox.go

Usage

List

list := []string{"alice", "bob", "carol", "dave"}
caption := "Who are you?"

// return selected element index
index, err := selector.List(list, caption)
if err != nil {
    log.Fatal(err)
    os.Exit(1)
}

// when typed ESC key
if index == -1 {
    fmt.Println("Not selected")
    os.Exit(0)
}

fmt.Println(index) //=> 1

Checkbox

list := []string{"alice", "bob", "carol", "dave"}
caption := "Whom do you like?"

// return slice into selected element indexes
index, err := selector.List(list, caption)
indexes, err := selector.Checkbox(list)
if err != nil {
    log.Fatal(err)
    os.Exit(1)
}

// when typed ESC key or seleted nothing
if len(indexes) == 0 {
    fmt.Println("Not selected")
    os.Exit(0)
}

fmt.Println(indexes) //=> [1 3]

Keybind

Key Description
Enter Decision
Esc Exit
Ctrl + n, j Move to choices below
Ctrl + p, k Move to choices above
Space Select (Checkbox)

Author

munisystem

About

An elegant list item selector for command line interface in Go

Resources

Stars

2 stars

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages