Documentation
¶
Overview ¶
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.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CommandOption ¶
Main struct to handle options for Command, Description, and the function that should be called
type Menu ¶
type Menu struct { Commands []CommandOption Options MenuOptions }
Menu struct encapsulates Commands and Options
func NewMenu ¶
func NewMenu(cmds []CommandOption, options MenuOptions) *Menu
Creates a new menu with options
type MenuOptions ¶
Menu options -- right now only sets prompt
func NewMenuOptions ¶
func NewMenuOptions(prompt string, length int) 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
Click to show internal directories.
Click to hide internal directories.