go-menu: github.com/turret-io/go-menu/menu Index | Files

package menu

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.

Index

Package Files

doc.go layout.go menu.go

type CommandOption Uses

type CommandOption struct {
    Command, Description string
    Function             func(args ...string) error
}

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 Uses

func NewMenu(cmds []CommandOption, options MenuOptions) *Menu

Creates a new menu with options

func (m *Menu) Start()

Wrapper for providing Stdin to the main menu loop

type MenuOptions struct {
    Prompt      string
    MenuLength  int
    MenuCommand string
}

MenuOptions sets prompt, character width of menu, and command used to display the menu

func NewMenuOptions Uses

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.