debugger/main.go

195 lines
4.0 KiB
Go
Raw Permalink Normal View History

2024-01-03 11:18:56 -06:00
package debugger
import (
2024-01-03 11:18:56 -06:00
"os"
"go.wit.com/gui"
"go.wit.com/lib/gadgets"
"go.wit.com/lib/gui/logsettings"
"go.wit.com/log"
2024-01-03 11:18:56 -06:00
)
/*
Creates a window helpful for debugging this package
*/
func DebugWindow() {
if me != nil {
log.Warn("Draw then Toggle() debuging window here")
me.bugWin.Toggle()
return
}
me = new(debuggerSettings)
me.treeRoot = gui.TreeRoot()
me.bugWin = gadgets.NewBasicWindow(me.treeRoot, "go.wit.com/gui debug window")
me.bugWin.Make()
DebugWindow2(me.bugWin.Box(), "Debug Tab")
2024-02-12 15:16:51 -06:00
me.bugWin.Show()
2024-01-03 11:18:56 -06:00
}
func DebugWindow2(newB *gui.Node, title string) *gui.Node {
var gr *gui.Node
2024-01-03 11:18:56 -06:00
//////////////////////// main debug things //////////////////////////////////
gr = newB.NewGroup("Debugging Windows:")
2024-01-03 11:18:56 -06:00
gr.NewButton("logging", func() {
logsettings.LogWindow()
2024-01-03 11:18:56 -06:00
})
gr.NewButton("Widgets Window", func() {
if me.widgets == nil {
me.widgets = DebugWidgetWindow()
return
}
me.widgets.Toggle()
2024-01-03 11:18:56 -06:00
})
gr.NewLabel("Force Quit:")
2024-01-03 11:18:56 -06:00
gr.NewButton("os.Exit()", func() {
2024-01-03 11:18:56 -06:00
os.Exit(0)
})
//////////////////////// window debugging things //////////////////////////////////
gr = newB.NewGroup("list things")
2024-01-03 11:18:56 -06:00
gr.NewButton("List Windows", func() {
dropdownWindow(gr)
2024-01-03 11:18:56 -06:00
})
gr.NewButton("List Window Widgets", func() {
dropdownWindowWidgets(gr)
2024-01-03 11:18:56 -06:00
})
gr.NewButton("Node.ListChildren(true)", func() {
if activeWidget == nil {
2024-01-03 11:18:56 -06:00
activeWidget = bugWin
}
activeWidget.ListChildren(true)
})
gr = newB.NewGroup("plugins")
gr.NewButton("List Toolkits", func() {
me.treeRoot.ListToolkits()
2024-01-03 11:18:56 -06:00
})
gr.NewButton("load toolkit 'nocui'", func() {
bugWin.LoadToolkit("nocui")
2024-01-03 11:18:56 -06:00
})
gr.NewButton("unload toolkit 'nocui'", func() {
bugWin.CloseToolkit("nocui")
})
gr.NewButton("load toolkit 'gocui'", func() {
2024-01-03 11:18:56 -06:00
bugWin.LoadToolkit("gocui")
})
gr.NewButton("unload toolkit 'gocui'", func() {
bugWin.CloseToolkit("gocui")
})
gr.NewButton("load toolkit 'andlabs'", func() {
2024-01-03 11:18:56 -06:00
bugWin.LoadToolkit("andlabs")
})
gr.NewButton("unload toolkit 'andlabs'", func() {
bugWin.CloseToolkit("andlabs")
})
gr = newB.NewGroup("Learn GO")
gr.NewButton("GO Language Internals", func() {
if me.golang == nil {
me.golang = DebugGolangWindow()
return
}
log.Warn("going to toggle golang window")
if me.golang.Ready() {
me.golang.Toggle()
}
})
gr.NewButton("GO Channels debug", func() {
if me.gochan == nil {
me.gochan = DebugGoChannels()
return
}
log.Warn("going to toggle go channels window")
if me.gochan.Ready() {
me.gochan.Toggle()
}
})
gr.NewButton("test conc", func() {
log.Log(WARN, "TODO: fix me")
// makeConc()
})
2024-01-03 11:18:56 -06:00
return newB
}
func dropdownWindow(p *gui.Node) {
var mapWindows map[string]*gui.Node
mapWindows = make(map[string]*gui.Node)
dd := p.NewDropdown()
2024-01-03 11:18:56 -06:00
dd.Custom = func() {
name := dd.String()
2024-01-03 11:18:56 -06:00
activeWidget = mapWindows[name]
setActiveWidget(activeWidget)
log.Log(INFO, "The Window was set to", name)
2024-01-03 11:18:56 -06:00
}
log.Log(INFO, "dd =", dd)
if activeWidget == nil {
2024-01-03 11:18:56 -06:00
// the debug window doesn't exist yet so you can't display the change
// TODO: make a fake binary tree for this(?)
return
}
// var last = ""
for _, child := range p.Children() {
log.Log(INFO, "\t\t", child.GetProgName())
dd.AddText(child.GetProgName())
2024-01-03 11:18:56 -06:00
// last = child.Name
mapWindows[child.GetProgName()] = child
if activeWidget == nil {
2024-01-03 11:18:56 -06:00
activeWidget = child
}
}
// dd.SetDropdownName(last)
}
func dropdownWindowWidgets(p *gui.Node) {
var mapWindows map[string]*gui.Node
mapWindows = make(map[string]*gui.Node)
dd := p.NewDropdown()
2024-01-03 11:18:56 -06:00
dd.Custom = func() {
name := dd.String()
2024-01-03 11:18:56 -06:00
activeWidget = mapWindows[name]
setActiveWidget(activeWidget)
}
log.Log(INFO, "dd =", dd)
// log.Log("dumpWidget() ", b, listChildrenDepth, defaultPadding, n.id, info)
var addDropdowns func(*gui.Node)
addDropdowns = func(n *gui.Node) {
2024-01-03 11:18:56 -06:00
// s := n.dumpWidget(true)
s := n.GetProgName()
dd.AddText(s)
2024-01-03 11:18:56 -06:00
mapWindows[s] = n
for _, child := range n.Children() {
addDropdowns(child)
}
}
// list everything in the binary tree
addDropdowns(bugWin)
}
func setActiveWidget(w *gui.Node) {
log.Warn("TODO: setActiveWidget()")
2024-01-03 11:18:56 -06:00
}