2024-01-15 15:17:51 -06:00
|
|
|
package logsettings
|
|
|
|
|
2024-01-18 01:34:00 -06:00
|
|
|
import (
|
2024-01-18 19:00:03 -06:00
|
|
|
"go.wit.com/gui"
|
2024-01-18 01:34:00 -06:00
|
|
|
"go.wit.com/lib/gadgets"
|
|
|
|
"go.wit.com/log"
|
2024-01-15 15:17:51 -06:00
|
|
|
)
|
|
|
|
|
2024-01-15 16:40:52 -06:00
|
|
|
// TODO: make sure this works without needing to be shown
|
2024-01-15 16:47:52 -06:00
|
|
|
// apparently due to me once committing v0.9.2 as go.wit.com/gui
|
|
|
|
// every version number must start above that
|
|
|
|
// this is a test commit to tag this as v0.10
|
2024-01-15 16:40:52 -06:00
|
|
|
|
2024-01-15 15:17:51 -06:00
|
|
|
func (d *LogSettings) Show() {
|
2024-01-18 01:34:00 -06:00
|
|
|
if !d.Ready() {
|
|
|
|
return
|
|
|
|
}
|
2024-01-15 15:17:51 -06:00
|
|
|
d.win.Show()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (d *LogSettings) Hide() {
|
2024-01-18 01:34:00 -06:00
|
|
|
if !d.Ready() {
|
|
|
|
return
|
|
|
|
}
|
2024-01-15 15:17:51 -06:00
|
|
|
d.win.Hide()
|
|
|
|
}
|
|
|
|
|
|
|
|
// alternates between showing and hiding the window
|
|
|
|
func (d *LogSettings) Toggle() {
|
2024-01-18 01:34:00 -06:00
|
|
|
if !d.Ready() {
|
|
|
|
return
|
|
|
|
}
|
2024-01-15 15:17:51 -06:00
|
|
|
d.win.Toggle()
|
|
|
|
}
|
|
|
|
|
|
|
|
// Let's you toggle on and off the various types of debugging output
|
|
|
|
// These checkboxes should be in the same order as the are printed
|
|
|
|
func (d *LogSettings) draw() {
|
|
|
|
var g *gui.Node
|
|
|
|
|
|
|
|
d.win = gadgets.NewBasicWindow(d.parent, "Debug Flags")
|
2024-01-20 20:04:05 -06:00
|
|
|
d.win.Make()
|
|
|
|
d.win.Draw()
|
2024-01-15 15:17:51 -06:00
|
|
|
g = d.win.Box().NewGroup("Show").Pad()
|
|
|
|
g = g.NewBox("bw vbox", false)
|
|
|
|
d.buttonG = g
|
|
|
|
|
2024-01-18 01:34:00 -06:00
|
|
|
g.NewButton("Redirect STDOUT to /tmp/", func() {
|
2024-02-12 15:22:38 -06:00
|
|
|
// log.SetTmp()
|
2024-01-15 15:17:51 -06:00
|
|
|
})
|
|
|
|
|
2024-01-18 01:34:00 -06:00
|
|
|
g.NewButton("restore defaults", func() {
|
2024-01-15 15:17:51 -06:00
|
|
|
for _, wg := range myLogGui.groups {
|
|
|
|
for _, f := range wg.flags {
|
2024-01-20 20:04:05 -06:00
|
|
|
f.RestoreDefault()
|
2024-01-15 15:17:51 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2024-01-18 01:34:00 -06:00
|
|
|
g.NewButton("all on", func() {
|
2024-01-15 15:17:51 -06:00
|
|
|
for _, wg := range myLogGui.groups {
|
|
|
|
for _, f := range wg.flags {
|
2024-01-20 20:04:05 -06:00
|
|
|
f.SetValue(true)
|
2024-01-15 15:17:51 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2024-01-18 01:34:00 -06:00
|
|
|
g.NewButton("all off", func() {
|
2024-01-15 15:17:51 -06:00
|
|
|
for _, wg := range myLogGui.groups {
|
|
|
|
for _, f := range wg.flags {
|
2024-01-20 20:04:05 -06:00
|
|
|
f.SetValue(false)
|
2024-01-15 15:17:51 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2024-01-18 01:34:00 -06:00
|
|
|
g.NewButton("Dump Flags", func() {
|
2024-01-15 15:17:51 -06:00
|
|
|
// ShowDebugValues()
|
|
|
|
log.ShowFlags()
|
|
|
|
for s, wg := range myLogGui.groups {
|
|
|
|
log.Info("Dump Flags", s)
|
|
|
|
for _, f := range wg.flags {
|
2024-01-20 20:04:05 -06:00
|
|
|
log.Info("Dump Flags\t", f.Bool(), f.GetName(), ":", f.GetDesc())
|
2024-01-15 15:17:51 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
d.flagG = d.win.Box().NewGroup("Subsystem (aka package)")
|
|
|
|
d.flagG = d.flagG.NewBox("bw vbox", false)
|
|
|
|
|
2024-01-18 01:34:00 -06:00
|
|
|
g.NewButton("Add all Flags", func() {
|
2024-01-15 15:17:51 -06:00
|
|
|
flags := log.ShowFlags()
|
|
|
|
for _, f := range flags {
|
|
|
|
addFlag(d.flagG, f)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2024-01-18 01:34:00 -06:00
|
|
|
g.NewButton("Close", func() {
|
2024-01-15 15:17:51 -06:00
|
|
|
d.Hide()
|
|
|
|
})
|
|
|
|
|
|
|
|
flags := log.ShowFlags()
|
|
|
|
for _, f := range flags {
|
|
|
|
addFlag(d.flagG, f)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func addFlag(p *gui.Node, newf *log.LogFlag) {
|
|
|
|
var flagWidgets *flagGroup
|
2024-01-18 01:34:00 -06:00
|
|
|
if newf == nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if p == nil {
|
|
|
|
return
|
|
|
|
}
|
2024-01-15 15:17:51 -06:00
|
|
|
|
|
|
|
subsys := newf.GetSubsystem()
|
|
|
|
|
|
|
|
if myLogGui.groups[subsys] == nil {
|
|
|
|
flagWidgets = new(flagGroup)
|
|
|
|
flagWidgets.parent = p
|
2024-01-20 20:04:05 -06:00
|
|
|
flagWidgets.group = p.NewGroup(newf.GetSubsystem())
|
2024-01-15 15:17:51 -06:00
|
|
|
flagWidgets.grid = flagWidgets.group.NewGrid("flags grid", 3, 1)
|
|
|
|
myLogGui.groups[subsys] = flagWidgets
|
|
|
|
} else {
|
|
|
|
flagWidgets = myLogGui.groups[subsys]
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, f := range flagWidgets.flags {
|
2024-01-20 20:04:05 -06:00
|
|
|
if f.GetName() == newf.GetName() {
|
2024-01-15 15:17:51 -06:00
|
|
|
log.Info("addFlag() FOUND FLAG", f)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
2024-01-20 20:04:05 -06:00
|
|
|
log.Info("addFlag() Adding new flag:", newf.GetSubsystem(), newf.GetName())
|
2024-01-15 15:17:51 -06:00
|
|
|
newWidget := gadgets.NewLogFlag(flagWidgets.grid, newf)
|
|
|
|
flagWidgets.flags = append(flagWidgets.flags, newWidget)
|
|
|
|
}
|
|
|
|
|
|
|
|
type flagGroup struct {
|
2024-01-18 01:34:00 -06:00
|
|
|
parent *gui.Node // where to draw our group
|
|
|
|
group *gui.Node
|
|
|
|
grid *gui.Node
|
2024-01-15 15:17:51 -06:00
|
|
|
|
|
|
|
// the widget for each flag
|
|
|
|
flags []*gadgets.LogFlag
|
|
|
|
}
|