summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeff Carr <[email protected]>2023-04-27 22:21:31 -0500
committerJeff Carr <[email protected]>2023-04-27 22:21:31 -0500
commita1deb9845593e211a1ce6fe4a7f88bbe5acd9981 (patch)
treee355d637606f34b2a17da4e9d84292596e175166
parent87b62c98a6ebd9d0e48850d1710de7f39aba41c8 (diff)
nocui: simulates button clicks
Signed-off-by: Jeff Carr <[email protected]>
-rw-r--r--cmds/buttonplugin/log.go11
-rw-r--r--toolkit/nocui/action.go23
-rw-r--r--toolkit/nocui/common.go19
-rw-r--r--toolkit/nocui/event.go65
-rw-r--r--toolkit/nocui/log.go31
-rw-r--r--toolkit/nocui/main.go3
-rw-r--r--toolkit/nocui/stdin.go76
7 files changed, 162 insertions, 66 deletions
diff --git a/cmds/buttonplugin/log.go b/cmds/buttonplugin/log.go
index 70039df..13238f4 100644
--- a/cmds/buttonplugin/log.go
+++ b/cmds/buttonplugin/log.go
@@ -2,12 +2,7 @@
package main
import (
- "log"
"fmt"
- "os"
- "io"
- "time"
- "bufio"
arg "github.com/alexflint/go-arg"
"git.wit.org/wit/gui"
)
@@ -21,14 +16,17 @@ var args struct {
gui.GuiArgs
}
+/*
var f1 *os.File
var f2 *os.File
var err error
+*/
func init() {
arg.MustParse(&args)
fmt.Println(args.Foo, args.Bar, args.User)
+/*
log.Println()
log.Println("STDOUT is now at /tmp/guilogfile")
log.Println("STDOUT is now at /tmp/guilogfile")
@@ -42,8 +40,10 @@ func init() {
log.SetOutput(f1)
log.Println("This is a test log entry")
+*/
}
+/*
func captureSTDOUT() {
f2, _ = os.OpenFile("/tmp/my.log", os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0664)
multiWriter := io.MultiWriter(os.Stderr, f2)
@@ -68,3 +68,4 @@ func captureSTDOUT() {
// hacky sleep to ensure the go routine can write before program exits
time.Sleep(time.Second)
}
+*/
diff --git a/toolkit/nocui/action.go b/toolkit/nocui/action.go
index 7b542ca..ea1a60e 100644
--- a/toolkit/nocui/action.go
+++ b/toolkit/nocui/action.go
@@ -81,9 +81,9 @@ func (n *node) Delete() {
}
}
-func action(a toolkit.Action) {
- log(logNow, "rawAction() START a.ActionType =", a.ActionType)
- log(logNow, "rawAction() START a.S =", a.S)
+func doAction(a *toolkit.Action) {
+ log(logNow, "doAction() START a.ActionType =", a.ActionType)
+ log(logNow, "doAction() START a.S =", a.S)
if (a.ActionType == toolkit.InitToolkit) {
// TODO: make sure to only do this once
@@ -95,8 +95,12 @@ func action(a toolkit.Action) {
return
}
- log(logNow, "rawAction() START a.WidgetId =", a.WidgetId, "a.ParentId =", a.ParentId)
+ log(logNow, "doAction() START a.WidgetId =", a.WidgetId, "a.ParentId =", a.ParentId)
switch a.WidgetType {
+ case toolkit.Root:
+ rootNode = addWidget(a)
+ log(logNow, "doAction() found rootNode")
+ return
case toolkit.Flag:
// flag(&a)
return
@@ -106,10 +110,7 @@ func action(a toolkit.Action) {
switch a.ActionType {
case toolkit.Add:
- // QueueMain(func() {
- // add(a)
- // })
- // sleep(.1)
+ addWidget(a)
case toolkit.Show:
n.show(true)
case toolkit.Hide:
@@ -142,11 +143,11 @@ func action(a toolkit.Action) {
case toolkit.Delete:
n.Delete()
case toolkit.Move:
- log(logNow, "rawAction() attempt to move() =", a.ActionType, a.WidgetType)
+ log(logNow, "doAction() attempt to move() =", a.ActionType, a.WidgetType)
newParent := rootNode.findWidgetId(a.ParentId)
n.move(newParent)
default:
- log(logError, "rawAction() Unknown =", a.ActionType, a.WidgetType)
+ log(logError, "doAction() Unknown =", a.ActionType, a.WidgetType)
}
- log(logInfo, "rawAction() END =", a.ActionType, a.WidgetType)
+ log(logInfo, "doAction() END =", a.ActionType, a.WidgetType)
}
diff --git a/toolkit/nocui/common.go b/toolkit/nocui/common.go
index 2e0ffdc..e68308d 100644
--- a/toolkit/nocui/common.go
+++ b/toolkit/nocui/common.go
@@ -58,22 +58,3 @@ func addWidget(a *toolkit.Action) *node {
}
return n
}
-
-func (n *node) doUserEvent() {
- if (callback == nil) {
- log(logError, "doUserEvent() callback == nil", n.WidgetId)
- return
- }
- var a toolkit.Action
- a.WidgetId = n.WidgetId
- a.Name = n.Name
- a.Text = n.Text
- a.S = n.S
- a.I = n.I
- a.B = n.B
- a.ActionType = toolkit.User
- log(logInfo, "doUserEvent() START: send a user event to the callback channel")
- callback <- a
- log(logInfo, "doUserEvent() END: sent a user event to the callback channel")
- return
-}
diff --git a/toolkit/nocui/event.go b/toolkit/nocui/event.go
new file mode 100644
index 0000000..ab2723f
--- /dev/null
+++ b/toolkit/nocui/event.go
@@ -0,0 +1,65 @@
+package main
+
+import (
+ "git.wit.org/wit/gui/toolkit"
+)
+
+func (n *node) doWidgetClick() {
+ switch n.WidgetType {
+ case toolkit.Root:
+ // THIS IS THE BEGINING OF THE LAYOUT
+ // rootNode.nextW = 0
+ // rootNode.nextH = 0
+ // rootNode.redoTabs(true)
+ case toolkit.Flag:
+ // me.rootNode.redoColor(true)
+ // rootNode.dumpTree(true)
+ case toolkit.Window:
+ // setCurrentWindow(w)
+ case toolkit.Tab:
+ // setCurrentTab(w)
+ case toolkit.Group:
+ // n.placeWidgets()
+ // n.toggleTree()
+ case toolkit.Checkbox:
+ if (n.B) {
+ // n.setCheckbox(false)
+ } else {
+ // n.setCheckbox(true)
+ }
+ n.doUserEvent()
+ case toolkit.Grid:
+ // rootNode.hideWidgets()
+ // n.placeGrid()
+ // n.showWidgets()
+ case toolkit.Box:
+ // n.showWidgetPlacement(logNow, "drawTree()")
+ if (n.B) {
+ log("BOX IS HORIZONTAL", n.Name)
+ } else {
+ log("BOX IS VERTICAL", n.Name)
+ }
+ case toolkit.Button:
+ n.doUserEvent()
+ default:
+ }
+}
+
+func (n *node) doUserEvent() {
+ if (callback == nil) {
+ log(logError, "doUserEvent() callback == nil", n.WidgetId)
+ return
+ }
+ var a toolkit.Action
+ a.WidgetId = n.WidgetId
+ a.Name = n.Name
+ a.Text = n.Text
+ a.S = n.S
+ a.I = n.I
+ a.B = n.B
+ a.ActionType = toolkit.User
+ log(logInfo, "doUserEvent() START: send a user event to the callback channel")
+ callback <- a
+ log(logInfo, "doUserEvent() END: sent a user event to the callback channel")
+ return
+}
diff --git a/toolkit/nocui/log.go b/toolkit/nocui/log.go
index baf57d9..306feed 100644
--- a/toolkit/nocui/log.go
+++ b/toolkit/nocui/log.go
@@ -1,9 +1,6 @@
package main
import (
- "io"
-// "fmt"
-// "strings"
witlog "git.wit.org/wit/gui/log"
)
@@ -17,7 +14,7 @@ var logVerbose bool = false
var outputS []string
func log(a ...any) {
- witlog.Where = "wit/gocui"
+ witlog.Where = "wit/nocui"
witlog.Log(a...)
}
@@ -28,29 +25,3 @@ func sleep(a ...any) {
func exit(a ...any) {
witlog.Exit(a...)
}
-
-/*
-func newLog(a ...any) {
- s := fmt.Sprint(a...)
- tmp := strings.Split(s, "\n")
- outputS = append(outputS, tmp...)
- if (len(outputS) > 50) {
- outputS = outputS[10:]
- }
- if (me.baseGui != nil) {
- v, _ := me.baseGui.View("msg")
- if (v != nil) {
- v.Clear()
- fmt.Fprintln(v, strings.Join(outputS, "\n"))
- }
- }
-}
-*/
-
-func setOutput(w io.Writer) {
- if (w == nil) {
- return
- }
- witlog.SetOutput(w)
- // witlog.SetToolkitOutput(newLog)
-}
diff --git a/toolkit/nocui/main.go b/toolkit/nocui/main.go
index 7309782..a957773 100644
--- a/toolkit/nocui/main.go
+++ b/toolkit/nocui/main.go
@@ -22,7 +22,7 @@ func catchActionChannel() {
log(logNow, "catchActionChannel() SELECT widget id =", a.WidgetId, a.Name)
log(logNow, "catchActionChannel() STUFF", a.WidgetId, a.ActionType, a.WidgetType)
muAction.Lock()
- action(a)
+ doAction(&a)
muAction.Unlock()
log(logNow, "catchActionChannel() STUFF END", a.WidgetId, a.ActionType, a.WidgetType)
}
@@ -54,5 +54,6 @@ func init() {
log(logNow, "Init() start channel reciever")
go catchActionChannel()
+ go simpleStdin()
log(logNow, "Init() END")
}
diff --git a/toolkit/nocui/stdin.go b/toolkit/nocui/stdin.go
new file mode 100644
index 0000000..ed71206
--- /dev/null
+++ b/toolkit/nocui/stdin.go
@@ -0,0 +1,76 @@
+package main
+
+import (
+ "os"
+ "fmt"
+ "bufio"
+ "strings"
+ "strconv"
+
+ "git.wit.org/wit/gui/toolkit"
+)
+
+func simpleStdin() {
+ scanner := bufio.NewScanner(os.Stdin)
+ for scanner.Scan() {
+ s := scanner.Text()
+ s = strings.TrimSuffix(s, "\n")
+ switch s {
+ case "l":
+ log(true, "list widgets")
+ rootNode.listWidgets()
+ case "b":
+ log(true, "show buttons")
+ rootNode.showButtons()
+ case "":
+ fmt.Println("")
+ fmt.Println("Enter:")
+ fmt.Println("'l': list all widgets")
+ fmt.Println("'b': for buttons")
+ fmt.Println("")
+ default:
+ i, _ := strconv.Atoi(s)
+ log(true, "got input:", i)
+ n := rootNode.findWidgetId(i)
+ if (n != nil) {
+ n.dumpWidget("found node")
+ n.doUserEvent()
+ }
+ }
+ }
+}
+
+func (n *node) showButtons() {
+ if n.WidgetType == toolkit.Button {
+ n.dumpWidget("Button:")
+ }
+
+ for _, child := range n.children {
+ child.showButtons()
+ }
+}
+
+func (n *node) dumpWidget(pad string) {
+ log(true, "node:", pad, n.WidgetId, ",", n.WidgetType, ",", n.Name)
+}
+
+var depth int = 0
+
+func (n *node) listWidgets() {
+ if (n == nil) {
+ return
+ }
+
+ var pad string
+ for i := 0; i < depth; i++ {
+ pad = pad + " "
+ }
+ n.dumpWidget(pad)
+
+ for _, child := range n.children {
+ depth += 1
+ child.listWidgets()
+ depth -= 1
+ }
+ return
+}