Giter VIP home page Giter VIP logo

wmenu's Introduction

WMenu Build Status Go Report Card GoDoc

Package wmenu creates menus for cli programs. It uses wlog for it's interface with the command line. It uses os.Stdin, os.Stdout, and os.Stderr with concurrency by default. wmenu allows you to change the color of the different parts of the menu. This package also creates it's own error structure so you can type assert if you need to. wmenu will validate all responses before calling any function. It will also figure out which function should be called so you don't have to.

Import

import "github.com/dixonwille/wmenu"

Features

  • Force single selection
  • Allow multiple selection
  • Change the delimiter
  • Change the color of different parts of the menu
  • Easily see which option(s) are default
  • Change the symbol used for default option(s)
  • Ask simple yes and no questions
  • Validate all responses before calling any functions
  • With yes and no can accept:
    • yes, Yes, YES, y, Y
    • no, No, NO, n, N
  • Figure out which Action should be called (Options, Default, or Multiple Action)
  • Re-ask question if invalid response up to a certain number of times
  • Can change max number of times to ask before failing output
  • Change reader and writer
  • Clear the screen whenever the menu is brought up
  • Has its own error structure so you can type assert menu errors

Usage

This is a simple use of the package.

menu := wmenu.NewMenu("What is your favorite food?")
menu.Action(func (opt Opt) error {fmt.Printf(opt.Text + " is your favorite food."); return nil})
menu.Option("Pizza", true, nil)
menu.Option("Ice Cream", false, nil)
menu.Option("Tacos", false, func() error {
  fmt.Printf("Tacos are great")
})
err := menu.Run()
if err != nil{
  log.Fatal(err)
}

The output would look like this:

0) *Pizza
1) Ice Cream
2) Tacos
What is your favorite food?

If the user just presses [Enter] then the option(s) with the * will be selected. This indicates that it is a default function. If they choose 1 then they would see Ice Cream is your favorite food.. This used the Action's function because the option selected didn't have a function along with it. But if they choose 2 they would see Tacos are great. That option did have a function with it which take precedence over Action.

You can you also use:

menu.MultipleAction(func (opt []Opt) error {return nil})

This will allow the user to select multiple options. The default delimiter is a [space], but can be changed by using:

menu.SetSeperator("some string")

Another feature is the ability to ask yes or no questions.

menu.IsYesNo(0)

This will remove any options previously added options and hide the ones used for the menu. It will simply just ask yes or no. Menu will parse and validate the response for you. This option will always call the Action's function and pass in the option that was selected.

Further Reading

This whole package has been documented and has a few examples in the godocs. You should read the docs to find all functions and structures at your finger tips.

wmenu's People

Contributors

dixonwille avatar jamesboswell avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.