-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
71 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,55 @@ | ||
# go-cli-select | ||
Lightweight menu selection library for CLI choices | ||
# Golang CLI Select | ||
Lightweight interactive CLI selection library | ||
|
||
|
||
## Import the package | ||
```go | ||
import "github.com/nexidian/gocliselect" | ||
``` | ||
|
||
## Usage | ||
Create a new menu, supplying the question as a parameter | ||
|
||
```go | ||
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 | ||
```go | ||
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()` | ||
|
||
```go | ||
choice := menu.Display() | ||
``` | ||
|
||
## Example | ||
```go | ||
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) | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,20 @@ | ||
package main | ||
|
||
import "github.com/nexidian/gocliselect" | ||
import ( | ||
"fmt" | ||
"github.com/nexidian/gocliselect" | ||
) | ||
|
||
func main() { | ||
menu := gocliselect.NewMenu("", "Select an option") | ||
menu := gocliselect.NewMenu("Chose a colour") | ||
|
||
menu.AddItem("Option 1", "option1") | ||
menu.AddItem("Option 2", "option2") | ||
menu.AddItem("Option 3", "option3") | ||
menu.AddItem("Option 4", "option4") | ||
menu.AddItem("Option 5", "option5") | ||
menu.AddItem("Red", "red") | ||
menu.AddItem("Blue", "blue") | ||
menu.AddItem("Green", "green") | ||
menu.AddItem("Yellow", "yellow") | ||
menu.AddItem("Cyan", "cyan") | ||
|
||
menu.Display() | ||
choice := menu.Display() | ||
|
||
fmt.Printf("Choice: %s\n", choice) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters