2024-01-18 00:11:03 -06:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bufio"
|
2024-01-18 04:08:32 -06:00
|
|
|
"fmt"
|
|
|
|
"os"
|
2024-01-18 00:11:03 -06:00
|
|
|
"runtime/debug"
|
|
|
|
"strconv"
|
2024-01-18 04:08:32 -06:00
|
|
|
"strings"
|
2024-01-18 00:11:03 -06:00
|
|
|
|
|
|
|
"go.wit.com/log"
|
2024-01-18 04:08:32 -06:00
|
|
|
"go.wit.com/widget"
|
2024-01-18 00:11:03 -06:00
|
|
|
)
|
|
|
|
|
2024-01-27 12:55:27 -06:00
|
|
|
func showOptions() {
|
|
|
|
fmt.Println("")
|
|
|
|
fmt.Println("Enter:")
|
|
|
|
fmt.Println("'l': list all widgets")
|
|
|
|
fmt.Println("'b': for buttons")
|
|
|
|
fmt.Println("'g': load gocui plugin")
|
|
|
|
fmt.Println("'a': load andlabs plugin")
|
|
|
|
fmt.Println("'d': enable debugging")
|
2024-01-30 11:34:00 -06:00
|
|
|
fmt.Println("'p': panic plugin")
|
|
|
|
fmt.Println("'q': close plugin")
|
2024-01-27 12:55:27 -06:00
|
|
|
fmt.Println("")
|
|
|
|
fmt.Println("Enter the number of the widget to click:")
|
|
|
|
fmt.Print("Option: ")
|
2024-02-01 21:53:38 -06:00
|
|
|
fmt.Fprintf(os.Stderr, "Option:\n")
|
|
|
|
fmt.Fprintf(os.Stderr, "Option: ")
|
2024-01-27 12:55:27 -06:00
|
|
|
}
|
|
|
|
|
2024-01-18 00:11:03 -06:00
|
|
|
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()
|
2024-01-19 02:58:45 -06:00
|
|
|
me.myTree.SendToolkitPanic()
|
2024-01-18 23:07:56 -06:00
|
|
|
return
|
2024-01-18 00:11:03 -06:00
|
|
|
}
|
|
|
|
}()
|
|
|
|
scanner := bufio.NewScanner(os.Stdin)
|
|
|
|
for scanner.Scan() {
|
2024-02-05 12:26:05 -06:00
|
|
|
if me.exit {
|
|
|
|
return
|
|
|
|
}
|
2024-01-18 00:11:03 -06:00
|
|
|
s := scanner.Text()
|
|
|
|
s = strings.TrimSuffix(s, "\n")
|
|
|
|
switch s {
|
|
|
|
case "l":
|
|
|
|
log.Log(NOW, "list widgets")
|
|
|
|
me.treeRoot.ListWidgets()
|
|
|
|
case "b":
|
|
|
|
log.Log(NOW, "show buttons")
|
|
|
|
me.treeRoot.ShowButtons()
|
|
|
|
case "g":
|
2024-01-19 02:58:45 -06:00
|
|
|
me.myTree.SendToolkitLoad("gocui")
|
2024-01-18 00:11:03 -06:00
|
|
|
case "a":
|
2024-01-19 02:58:45 -06:00
|
|
|
me.myTree.SendToolkitLoad("andlabs")
|
2024-01-18 00:11:03 -06:00
|
|
|
case "d":
|
2024-01-19 02:58:45 -06:00
|
|
|
me.myTree.SendEnableDebugger()
|
2024-01-30 11:34:00 -06:00
|
|
|
case "p":
|
|
|
|
debug.PrintStack()
|
|
|
|
me.myTree.SendToolkitPanic()
|
|
|
|
return
|
|
|
|
case "q":
|
|
|
|
return
|
2024-01-18 00:11:03 -06:00
|
|
|
case "":
|
2024-01-27 12:55:27 -06:00
|
|
|
showOptions()
|
2024-01-18 00:11:03 -06:00
|
|
|
default:
|
|
|
|
i, _ := strconv.Atoi(s)
|
|
|
|
log.Log(NOW, "got input:", i)
|
|
|
|
n := me.treeRoot.FindWidgetId(i)
|
2024-01-18 04:08:32 -06:00
|
|
|
if n != nil {
|
2024-01-18 00:11:03 -06:00
|
|
|
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:
|
2024-01-19 02:58:45 -06:00
|
|
|
me.myTree.SendUserEvent(n)
|
2024-01-18 00:11:03 -06:00
|
|
|
case widget.Checkbox:
|
2024-01-19 02:58:45 -06:00
|
|
|
me.myTree.SendUserEvent(n)
|
2024-01-18 00:11:03 -06:00
|
|
|
default:
|
|
|
|
log.Warn("you haven't defined an event for", n.WidgetType)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2024-01-27 12:55:27 -06:00
|
|
|
showOptions()
|
2024-01-18 00:11:03 -06:00
|
|
|
}
|
|
|
|
}
|