pixelgl/stdin.go

111 lines
2.5 KiB
Go

package main
import (
"bufio"
"fmt"
"os"
"runtime/debug"
"strconv"
"strings"
"github.com/faiface/pixel/pixelgl"
"github.com/gookit/config"
"go.wit.com/log"
"go.wit.com/toolkits/tree"
"go.wit.com/widget"
)
func showOptions() {
fmt.Println("")
fmt.Println("Enter:")
fmt.Println("")
fmt.Println("This doesn't work because it's stalled in the toolkit init()")
fmt.Println("opengl isn't happy if you try to run it as a goroutine and exits")
fmt.Println("maybe there is someone that actually knows what the are doing that can fix that")
fmt.Println("")
fmt.Println("'l': list all widgets")
fmt.Println("'b': for buttons")
fmt.Println("'g': try opengl")
fmt.Println("'a': load andlabs plugin")
fmt.Println("'d': enable debugging")
fmt.Println("'p': panic plugin")
fmt.Println("'q': close plugin")
fmt.Println("")
fmt.Println("Enter the number of the widget to click:")
fmt.Print("Option: ")
fmt.Fprintf(os.Stderr, "Option:\n")
fmt.Fprintf(os.Stderr, "Option: ")
}
func simpleStdin() {
defer func() {
if r := recover(); r != nil {
log.Warn("nocui YAHOOOO Recovered in simpleStdin()", r)
log.Println("Recovered from panic:", r)
log.Println("Stack trace:")
debug.PrintStack()
me.myTree.SendToolkitPanic()
os.Exit(0)
return
}
}()
scanner := bufio.NewScanner(os.Stdin)
for scanner.Scan() {
if me.exit {
return
}
s := scanner.Text()
s = strings.TrimSuffix(s, "\n")
switch s {
case "l":
log.Log(NOW, "list widgets")
tree.ListWidgets()
case "b":
log.Log(NOW, "show buttons")
tree.ShowButtons()
case "g":
config.Set("width", 1024)
config.Set("height", 768)
config.Set("glDrift", 0.01)
config.Set("filename", "seascape.glsl")
pixelgl.Run(run)
case "a":
me.myTree.SendToolkitLoad("andlabs")
case "d":
me.myTree.SendEnableDebugger()
case "p":
debug.PrintStack()
me.myTree.SendToolkitPanic()
os.Exit(0)
return
case "q":
return
case "":
showOptions()
default:
i, _ := strconv.Atoi(s)
log.Log(NOW, "got input:", i)
n := tree.FindWidgetId(i)
if n != nil {
n.DumpWidget("found node")
for i, s := range n.State.Strings {
log.Warn("n.State.Strings =", i, s)
}
switch n.WidgetType {
case widget.Root:
log.Warn("this is the root widget")
case widget.Dropdown:
log.Warn("print out dropdown values here")
case widget.Button:
me.myTree.SendUserEvent(n)
case widget.Checkbox:
me.myTree.SendUserEvent(n)
default:
log.Warn("you haven't defined an event for", n.WidgetType)
}
}
}
showOptions()
}
}