Skip to content

Commit

Permalink
Try and fix the clear command for tests
Browse files Browse the repository at this point in the history
Signed-off-by: Will Dixon <will@willd.io>
  • Loading branch information
dixonwille committed Oct 30, 2023
1 parent a0c2cee commit 1f9bd62
Show file tree
Hide file tree
Showing 4 changed files with 127 additions and 156 deletions.
16 changes: 4 additions & 12 deletions clearScreen.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package wmenu

import (
"fmt"
"os"
"os/exec"
"runtime"
Expand All @@ -11,24 +12,15 @@ var clear map[string]func()
func init() {
clear = make(map[string]func())
clear["linux"] = func() {
cmd := exec.Command("clear")
cmd.Stdout = os.Stdout
err := cmd.Run()
if err != nil {
panic(err)
}
fmt.Print("\033[2J\033[H")
}
clear["darwin"] = func() {
cmd := exec.Command("clear")
cmd.Stdout = os.Stdout
err := cmd.Run()
if err != nil {
panic(err)
}
fmt.Print("\033[2J\033[H")
}
clear["windows"] = func() {
cmd := exec.Command("cmd", "/c", "cls")
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
err := cmd.Run()
if err != nil {
panic(err)
Expand Down
26 changes: 0 additions & 26 deletions clearScreen_test.go

This file was deleted.

5 changes: 3 additions & 2 deletions example/main.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//package main is to show how multiple menus can be used with eachother
// package main is to show how multiple menus can be used with each other
package main

import (
Expand Down Expand Up @@ -36,7 +36,7 @@ func mainMenu() *wmenu.Menu {
menu := wmenu.NewMenu("What is your favorite food?")
menu.Option(menuItemStrings[pizza], pizza, true, nil)
menu.Option(menuItemStrings[iceCream], iceCream, false, nil)
menu.Option(menuItemStrings[tacos], tacos, false, func(opt wmenu.Opt) error {
menu.Option(menuItemStrings[tacos], tacos, false, func(_ wmenu.Opt) error {
fmt.Printf("Tacos are great!\n")
return nil
})
Expand All @@ -53,6 +53,7 @@ func mainMenu() *wmenu.Menu {

func toppingsMenu(favorite menuItem) *wmenu.Menu {
menu := wmenu.NewMenu(fmt.Sprintf("What is your favorite topping for %s?", menuItemStrings[favorite]))
menu.ClearOnMenuRun()
if favorite == pizza {
menu.Option("Meat", nil, true, nil)
menu.Option("Cheese", nil, false, nil)
Expand Down
Loading

0 comments on commit 1f9bd62

Please sign in to comment.