gocui: smarter debugging
Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
parent
821e6d823a
commit
462015470d
|
@ -4,7 +4,7 @@ package main
|
|||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"time"
|
||||
// "time"
|
||||
"strconv"
|
||||
"git.wit.org/wit/gui"
|
||||
)
|
||||
|
@ -16,24 +16,15 @@ var myGui *gui.Node
|
|||
var buttonCounter int = 5
|
||||
|
||||
func main() {
|
||||
// time.Sleep(5 * time.Second)
|
||||
// var w *gui.Node
|
||||
|
||||
// this doesn't seem to work
|
||||
// captureSTDOUT()
|
||||
|
||||
// gui.LoadToolkit("default")
|
||||
// panic("WTF gocui not happening")
|
||||
// gui.LoadToolkit("gocui")
|
||||
// gui.Init()
|
||||
|
||||
// buttonWindow()
|
||||
gui.SetDebug(true)
|
||||
// This will turn on all debugging
|
||||
// gui.SetDebug(true)
|
||||
myGui = gui.Start()
|
||||
time.Sleep(1 * time.Second)
|
||||
// time.Sleep(1 * time.Second)
|
||||
buttonWindow()
|
||||
log.Println("Main() END")
|
||||
time.Sleep(1 * time.Second)
|
||||
// time.Sleep(1 * time.Second)
|
||||
|
||||
// This is just a optional goroutine to watch that things are alive
|
||||
gui.Watchdog()
|
||||
gui.StandardExit()
|
||||
}
|
||||
|
|
12
main.go
12
main.go
|
@ -107,17 +107,17 @@ func Start() *Node {
|
|||
}
|
||||
|
||||
func watchCallback() {
|
||||
log(logNow, "makeCallback() START")
|
||||
log(logInfo, "watchCallback() START")
|
||||
for {
|
||||
log(logNow, "makeCallback() for loop")
|
||||
log(logNow, "watchCallback() restarted select for toolkit user events")
|
||||
select {
|
||||
case a := <-Config.guiChan:
|
||||
log(logNow, "makeCallback() SELECT widget id =", a.WidgetId, a.Name)
|
||||
n := Config.rootNode.FindId(a.WidgetId)
|
||||
if (n == nil) {
|
||||
log(logError, "makeCallback() SELECT widget id =", a.WidgetId, a.Name)
|
||||
log(logError, "watchCallback() UNKNOWN widget id =", a.WidgetId, a.Name)
|
||||
} else {
|
||||
go n.doUserEvent(a)
|
||||
log(logNow, "watchCallback() FOUND widget id =", n.id, n.Name)
|
||||
n.doUserEvent(a)
|
||||
}
|
||||
// this maybe a good idea?
|
||||
// TODO: Throttle user events somehow
|
||||
|
@ -132,7 +132,7 @@ func (n *Node) doCustom() {
|
|||
log(debugError, "Custom() = nil. SKIPPING")
|
||||
return
|
||||
}
|
||||
n.Custom()
|
||||
go n.Custom()
|
||||
}
|
||||
|
||||
func (n *Node) doUserEvent(a toolkit.Action) {
|
||||
|
|
24
plugin.go
24
plugin.go
|
@ -69,13 +69,13 @@ func LoadToolkit(name string) *aplug {
|
|||
var newPlug *aplug
|
||||
newPlug = new(aplug)
|
||||
|
||||
log(debugGui, "gui.LoadToolkit() START")
|
||||
log(logInfo, "LoadToolkit() START")
|
||||
newPlug.LoadOk = false
|
||||
|
||||
for _, aplug := range allPlugins {
|
||||
log(debugGui, "gui.LoadToolkit() already loaded toolkit plugin =", aplug.name)
|
||||
log(debugGui, "LoadToolkit() already loaded toolkit plugin =", aplug.name)
|
||||
if (aplug.name == name) {
|
||||
log(debugError, "gui.LoadToolkit() SKIPPING", name, "as you can't load it twice")
|
||||
log(debugError, "LoadToolkit() SKIPPING", name, "as you can't load it twice")
|
||||
return aplug
|
||||
}
|
||||
}
|
||||
|
@ -116,7 +116,7 @@ func LoadToolkit(name string) *aplug {
|
|||
|
||||
allPlugins = append(allPlugins, newPlug)
|
||||
|
||||
log(debugPlugin, "gui.LoadToolkit() END", newPlug.name, filename)
|
||||
log(debugPlugin, "LoadToolkit() END", newPlug.name, filename)
|
||||
newPlug.Init()
|
||||
newPlug.pluginChan = newPlug.PluginChannel()
|
||||
|
||||
|
@ -310,12 +310,12 @@ func newaction(a *toolkit.Action, n *Node, where *Node) {
|
|||
|
||||
// TODO: redo this grid logic
|
||||
if (where != nil) {
|
||||
log(debugGui, "Action() START on where X,Y, Next X,Y =", where.Name, where.X, where.Y, where.NextX, where.NextY)
|
||||
log(logInfo, "Action() START on where X,Y, Next X,Y =", where.Name, where.X, where.Y, where.NextX, where.NextY)
|
||||
a.ParentId = where.id
|
||||
switch where.widget.Type {
|
||||
case toolkit.Grid:
|
||||
// where.Dump(true)
|
||||
log(debugGui, "Action() START on Grid (X,Y)", where.X, where.Y, "put next thing at (X,Y) =", where.NextX, where.NextY)
|
||||
log(logInfo, "Action() START on Grid (X,Y)", where.X, where.Y, "put next thing at (X,Y) =", where.NextX, where.NextY)
|
||||
//
|
||||
// fix values here if they are invalid. Index starts at 1
|
||||
if (where.NextX < 1) {
|
||||
|
@ -327,7 +327,7 @@ func newaction(a *toolkit.Action, n *Node, where *Node) {
|
|||
//
|
||||
a.X = where.NextX
|
||||
a.Y = where.NextY
|
||||
log(debugGui, "Action() END on Grid (X,Y)", where.X, where.Y, "put next thing at (X,Y) =", where.NextX, where.NextY)
|
||||
log(logInfo, "Action() END on Grid (X,Y)", where.X, where.Y, "put next thing at (X,Y) =", where.NextX, where.NextY)
|
||||
default:
|
||||
}
|
||||
}
|
||||
|
@ -335,15 +335,13 @@ func newaction(a *toolkit.Action, n *Node, where *Node) {
|
|||
for _, aplug := range allPlugins {
|
||||
log(debugPlugin, "Action() aplug =", aplug.name, "Action type=", a.ActionType)
|
||||
if (aplug.pluginChan == nil) {
|
||||
log(debugNow, "Action() retrieving the aplug.PluginChannel()", aplug.name)
|
||||
log(logInfo, "Action() retrieving the aplug.PluginChannel()", aplug.name)
|
||||
aplug.pluginChan = aplug.PluginChannel()
|
||||
log(debugNow, "Action() retrieved", aplug.pluginChan)
|
||||
log(logInfo, "Action() retrieved", aplug.pluginChan)
|
||||
}
|
||||
log(debugNow, "Action() SEND pluginChan", aplug.name)
|
||||
log(debugNow, "Action() SEND pluginChan", aplug.name)
|
||||
log(debugNow, "Action() SEND pluginChan", aplug.name)
|
||||
log(logInfo, "Action() SEND to pluginChan", aplug.name)
|
||||
aplug.pluginChan <- *a
|
||||
sleep(.2)
|
||||
sleep(.02)
|
||||
}
|
||||
// increment where to put the next widget in a grid or table
|
||||
if (where != nil) {
|
||||
|
|
|
@ -2,27 +2,8 @@ package main
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"git.wit.org/wit/gui/toolkit"
|
||||
// "github.com/awesome-gocui/gocui"
|
||||
)
|
||||
|
||||
// var debugAction bool = false
|
||||
|
||||
func actionDump(b bool, a *toolkit.Action) {
|
||||
if (a == nil) {
|
||||
log(b, "action = nil")
|
||||
return
|
||||
}
|
||||
|
||||
log(b, "a.Name =", a.Name)
|
||||
log(b, "a.Text =", a.Text)
|
||||
log(b, "a.WidgetId =", a.WidgetId)
|
||||
log(b, "a.ParentId =", a.ParentId)
|
||||
log(b, "a.B =", a.B)
|
||||
log(b, "a.S =", a.S)
|
||||
}
|
||||
|
||||
func (w *cuiWidget) dumpTree(draw bool) {
|
||||
if (w == nil) {
|
||||
return
|
||||
|
|
|
@ -8,9 +8,9 @@ import (
|
|||
// various debugging flags
|
||||
var logNow bool = true // useful for active development
|
||||
var logError bool = true
|
||||
var logWarn bool = true
|
||||
var logInfo bool = true
|
||||
var logVerbose bool = true
|
||||
var logWarn bool = false
|
||||
var logInfo bool = false
|
||||
var logVerbose bool = false
|
||||
|
||||
func log(a ...any) {
|
||||
witlog.Where = "wit/gocui"
|
||||
|
|
|
@ -9,6 +9,8 @@ import (
|
|||
"git.wit.org/wit/gui/toolkit"
|
||||
)
|
||||
|
||||
// sets defaults and establishes communication
|
||||
// to this toolkit from the wit/gui golang package
|
||||
func Init() {
|
||||
log(logInfo, "Init() of awesome-gocui")
|
||||
me.defaultWidth = 10
|
||||
|
@ -43,20 +45,19 @@ func PluginChannel() chan toolkit.Action {
|
|||
}
|
||||
|
||||
func catchActionChannel() {
|
||||
log(logNow, "makeCallback() START")
|
||||
log(logInfo, "catchActionChannel() START")
|
||||
for {
|
||||
log(logNow, "makeCallback() for loop")
|
||||
log(logInfo, "catchActionChannel() infinite for() loop restarted select on channel")
|
||||
select {
|
||||
case a := <-me.pluginChan:
|
||||
log(logNow, "makeCallback() SELECT widget id =", a.WidgetId, a.Name)
|
||||
log(logNow, "catchActionChannel()", a.WidgetId, a.ActionType, a.WidgetType, a.Name)
|
||||
action(&a)
|
||||
sleep(.1)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func Exit() {
|
||||
// TODO: send exit to the plugin
|
||||
// TODO: what should actually happen here?
|
||||
me.baseGui.Close()
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue