Last active
October 8, 2017 23:29
-
-
Save binkybear/092d64035659bea5c55e5336ae0a2dec to your computer and use it in GitHub Desktop.
Yes or no menu in golang
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"log" | |
"github.com/dixonwille/wmenu" | |
) | |
func main() { | |
// Do this if yes or no | |
actFunc := func(opts []wmenu.Opt) error { | |
if opts[0].ID == 0 { // If yes, do this | |
fmt.Println("hello world") | |
} | |
if opts[0].ID == 1 { // If no, do this | |
fmt.Println("goodbye world") | |
} | |
// DEBUG | |
//fmt.Printf("%s has an id of %d.\n", opts[0].Text, opts[0].ID) | |
//fmt.Printf("But has a value of %s.\n", opts[0].Value.(string)) | |
return nil | |
} | |
// Start menu | |
menu := wmenu.NewMenu("Would you like to start?") // The yes or no question | |
menu.Action(actFunc) | |
menu.IsYesNo(0) | |
err := menu.Run() | |
if err != nil { | |
log.Fatal(err) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment