changed playground to make it less error prone and easier to add programs
This commit is contained in:
		@@ -8,56 +8,118 @@ import (
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
func main() {
 | 
			
		||||
	type program struct {
 | 
			
		||||
		name           string
 | 
			
		||||
		launchFunction func()
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	programs := []program{
 | 
			
		||||
		{
 | 
			
		||||
			name: "Pass or Fail",
 | 
			
		||||
			launchFunction: func() {
 | 
			
		||||
				passFail()
 | 
			
		||||
			},
 | 
			
		||||
		},
 | 
			
		||||
		{
 | 
			
		||||
			name: "Guessing Game",
 | 
			
		||||
			launchFunction: func() {
 | 
			
		||||
				guess()
 | 
			
		||||
			},
 | 
			
		||||
		},
 | 
			
		||||
		{
 | 
			
		||||
			name: "Shopping List",
 | 
			
		||||
			launchFunction: func() {
 | 
			
		||||
				shopping()
 | 
			
		||||
			},
 | 
			
		||||
		},
 | 
			
		||||
		{
 | 
			
		||||
			name: "Commandline Test",
 | 
			
		||||
			launchFunction: func() {
 | 
			
		||||
				terminalTest()
 | 
			
		||||
			},
 | 
			
		||||
		},
 | 
			
		||||
		{
 | 
			
		||||
			name: "Wall Area",
 | 
			
		||||
			launchFunction: func() {
 | 
			
		||||
				wallArea()
 | 
			
		||||
			},
 | 
			
		||||
		},
 | 
			
		||||
		{
 | 
			
		||||
			name: "myIntPointer",
 | 
			
		||||
			launchFunction: func() {
 | 
			
		||||
				myIntPointer()
 | 
			
		||||
			},
 | 
			
		||||
		},
 | 
			
		||||
		{
 | 
			
		||||
			name: "Double",
 | 
			
		||||
			launchFunction: func() {
 | 
			
		||||
				double()
 | 
			
		||||
			},
 | 
			
		||||
		},
 | 
			
		||||
		{
 | 
			
		||||
			name: "Convert To Celsius",
 | 
			
		||||
			launchFunction: func() {
 | 
			
		||||
				toCelsius()
 | 
			
		||||
			},
 | 
			
		||||
		},
 | 
			
		||||
		{
 | 
			
		||||
			name: "Get the Average My Solution",
 | 
			
		||||
			launchFunction: func() {
 | 
			
		||||
				averageMySolution()
 | 
			
		||||
			},
 | 
			
		||||
		},
 | 
			
		||||
		{
 | 
			
		||||
			name: "Get the Average Head First Solution",
 | 
			
		||||
			launchFunction: func() {
 | 
			
		||||
				averageHeadFirstSolution()
 | 
			
		||||
			},
 | 
			
		||||
		},
 | 
			
		||||
		{
 | 
			
		||||
			name: "Get the Average Variadic",
 | 
			
		||||
			launchFunction: func() {
 | 
			
		||||
				averageVariadic()
 | 
			
		||||
			},
 | 
			
		||||
		},
 | 
			
		||||
		{
 | 
			
		||||
			name: "Slices",
 | 
			
		||||
			launchFunction: func() {
 | 
			
		||||
				slices()
 | 
			
		||||
			},
 | 
			
		||||
		},
 | 
			
		||||
		{
 | 
			
		||||
			name: "Variadic Functions",
 | 
			
		||||
			launchFunction: func() {
 | 
			
		||||
				variadic()
 | 
			
		||||
			},
 | 
			
		||||
		},
 | 
			
		||||
		{
 | 
			
		||||
			name: "Count Votes",
 | 
			
		||||
			launchFunction: func() {
 | 
			
		||||
				countVotes()
 | 
			
		||||
			},
 | 
			
		||||
		},
 | 
			
		||||
		{
 | 
			
		||||
			name: "Magazine Subscribers",
 | 
			
		||||
			launchFunction: func() {
 | 
			
		||||
				magazineSubscribers()
 | 
			
		||||
			},
 | 
			
		||||
		},
 | 
			
		||||
	}
 | 
			
		||||
	menu := wmenu.NewMenu("Choose a program.")
 | 
			
		||||
	menu.Action(func(opts []wmenu.Opt) error {
 | 
			
		||||
		fmt.Printf("You chose " + opts[0].Text + ". Launching...\n")
 | 
			
		||||
		switch opts[0].Text {
 | 
			
		||||
		case "Pass or Fail":
 | 
			
		||||
			passFail()
 | 
			
		||||
		case "Guessing Game":
 | 
			
		||||
			guess()
 | 
			
		||||
		case "Shopping List":
 | 
			
		||||
			shopping()
 | 
			
		||||
		case "Commandline Test":
 | 
			
		||||
			terminalTest()
 | 
			
		||||
		case "Wall Area":
 | 
			
		||||
			wallArea()
 | 
			
		||||
		case "myIntPointer":
 | 
			
		||||
			myIntPointer()
 | 
			
		||||
		case "Double":
 | 
			
		||||
			double()
 | 
			
		||||
		case "Convert To Celsius":
 | 
			
		||||
			toCelsius()
 | 
			
		||||
		case "Get the Average My Solution":
 | 
			
		||||
			averageMySolution()
 | 
			
		||||
		case "Get the Average Head First Solution":
 | 
			
		||||
			averageHeadFirstSolution()
 | 
			
		||||
		case "Get the Average Variadic":
 | 
			
		||||
			averageVariadic()
 | 
			
		||||
		case "Slices":
 | 
			
		||||
			slices()
 | 
			
		||||
		case "Variadic Functions":
 | 
			
		||||
			variadic()
 | 
			
		||||
		case "Count Votes":
 | 
			
		||||
			countVotes()
 | 
			
		||||
		for _, v := range programs {
 | 
			
		||||
			if v.name == opts[0].Text {
 | 
			
		||||
				v.launchFunction()
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		return nil
 | 
			
		||||
	})
 | 
			
		||||
	menu.PadOptionID()
 | 
			
		||||
	menu.Option("Pass or Fail", nil, false, nil)
 | 
			
		||||
	menu.Option("Guessing Game", nil, false, nil)
 | 
			
		||||
	menu.Option("Shopping List", nil, false, nil)
 | 
			
		||||
	menu.Option("Commandline Test", nil, false, nil)
 | 
			
		||||
	menu.Option("Wall Area", nil, false, nil)
 | 
			
		||||
	menu.Option("myIntPointer", nil, false, nil)
 | 
			
		||||
	menu.Option("Double", nil, false, nil)
 | 
			
		||||
	menu.Option("Convert To Celsius", nil, false, nil)
 | 
			
		||||
	menu.Option("Get the Average My Solution", nil, false, nil)
 | 
			
		||||
	menu.Option("Get the Average Head First Solution", nil, false, nil)
 | 
			
		||||
	menu.Option("Get the Average Variadic", nil, false, nil)
 | 
			
		||||
	menu.Option("Slices", nil, false, nil)
 | 
			
		||||
	menu.Option("Variadic Functions", nil, false, nil)
 | 
			
		||||
	menu.Option("Count Votes", nil, false, nil)
 | 
			
		||||
	for _, option := range programs {
 | 
			
		||||
		menu.Option(option.name, nil, false, nil)
 | 
			
		||||
	}
 | 
			
		||||
	err := menu.Run()
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		log.Fatal(err)
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user