import "github.com/turret-io/go-menu/menu"
The go-menu package provides a library to build simple, interactive, command line menus in Go.
Installation:
import "github.com/turret-io/go-menu/menu"
Example:
func cmd1(args ...string) error { // Do something fmt.Println("Output of cmd1") return nil } func cmd2(args ...string) error { //Do something fmt.Println("Output of cmd2") return nil } func main() { commandOptions := []menu.CommandOption{ menu.CommandOption{"command1", "Runs command1", cmd1}, menu.CommandOption{"command2", "Runs command2", cmd2}, } menuOptions := menu.NewMenuOptions("'menu' for help > ", 0) menu := menu.NewMenu(commandOptions, menuOptions) menu.Start() }
Notes:
Typing "exit" or "quit" at the prompt will exit the program.
Typing "menu" will display the menu.
Main struct to handle options for Command, Description, and the function that should be called
type Menu struct { Commands []CommandOption Options MenuOptions }
Menu struct encapsulates Commands and Options
func NewMenu(cmds []CommandOption, options MenuOptions) *Menu
Creates a new menu with options
Wrapper for providing Stdin to the main menu loop
MenuOptions sets prompt, character width of menu, and command used to display the menu
func NewMenuOptions(prompt string, length int, menuCommand string) MenuOptions
Setup the options for the menu.
An empty string for prompt and a length of 0 will use the default "> " prompt and 100 character wide menu. An empty string for menuCommand will use the default 'menu' command.
Package menu imports 6 packages (graph) and is imported by 5 packages. Updated 2017-03-21. Refresh now. Tools for package owners.