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