menu

package
Version: v1.0.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 12, 2015 License: MIT Imports: 6 Imported by: 0

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

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

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
}

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

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL