From 462015470d3b1a0eac6693ab60875a7322595eb8 Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Sat, 8 Apr 2023 14:31:00 -0500 Subject: [PATCH] gocui: smarter debugging Signed-off-by: Jeff Carr --- cmds/buttonplugin/main.go | 23 +++++++---------------- main.go | 12 ++++++------ plugin.go | 24 +++++++++++------------- toolkit/gocui/debug.go | 19 ------------------- toolkit/gocui/log.go | 6 +++--- toolkit/gocui/main.go | 11 ++++++----- 6 files changed, 33 insertions(+), 62 deletions(-) diff --git a/cmds/buttonplugin/main.go b/cmds/buttonplugin/main.go index f33065a..8b94da2 100644 --- a/cmds/buttonplugin/main.go +++ b/cmds/buttonplugin/main.go @@ -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() } diff --git a/main.go b/main.go index 8e469e1..3026ae6 100644 --- a/main.go +++ b/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) { diff --git a/plugin.go b/plugin.go index 939107a..00a9064 100644 --- a/plugin.go +++ b/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) { diff --git a/toolkit/gocui/debug.go b/toolkit/gocui/debug.go index e569872..9b57b08 100644 --- a/toolkit/gocui/debug.go +++ b/toolkit/gocui/debug.go @@ -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 diff --git a/toolkit/gocui/log.go b/toolkit/gocui/log.go index 44bcf6c..222332d 100644 --- a/toolkit/gocui/log.go +++ b/toolkit/gocui/log.go @@ -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" diff --git a/toolkit/gocui/main.go b/toolkit/gocui/main.go index ed9670a..e2ec85f 100644 --- a/toolkit/gocui/main.go +++ b/toolkit/gocui/main.go @@ -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() }