summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeff Carr <[email protected]>2024-01-15 15:17:51 -0600
committerJeff Carr <[email protected]>2024-01-15 15:17:51 -0600
commit88fbc620e597108759c9929d263d57c4b7ee6b0b (patch)
tree84eed9c295bf8387f8ce1d018ab719081c4c65f7
initial repo
-rw-r--r--draw.go133
-rw-r--r--settings.go43
-rw-r--r--structs.go22
3 files changed, 198 insertions, 0 deletions
diff --git a/draw.go b/draw.go
new file mode 100644
index 0000000..d0d194a
--- /dev/null
+++ b/draw.go
@@ -0,0 +1,133 @@
+package logsettings
+
+import (
+ "go.wit.com/log"
+ "go.wit.com/gui/gui"
+ "go.wit.com/gui/gadgets"
+)
+
+func (d *LogSettings) Show() {
+ if ! d.Ready() { return }
+ d.win.Show()
+}
+
+func (d *LogSettings) Hide() {
+ if ! d.Ready() { return }
+ d.win.Hide()
+}
+
+// alternates between showing and hiding the window
+func (d *LogSettings) Toggle() {
+ if ! d.Ready() { return }
+ 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")
+ g = d.win.Box().NewGroup("Show").Pad()
+ g = g.NewBox("bw vbox", false)
+ d.buttonG = g
+
+ g.NewButton("Redirect STDOUT to /tmp/", func () {
+ log.SetTmp()
+ })
+
+ g.NewButton("restore defaults", func () {
+ for _, wg := range myLogGui.groups {
+ for _, f := range wg.flags {
+ f.SetDefault()
+ }
+ }
+ })
+
+ g.NewButton("all on", func () {
+ for _, wg := range myLogGui.groups {
+ for _, f := range wg.flags {
+ f.Set(true)
+ }
+ }
+ })
+
+ g.NewButton("all off", func () {
+ for _, wg := range myLogGui.groups {
+ for _, f := range wg.flags {
+ f.Set(false)
+ }
+ }
+ })
+
+ g.NewButton("Dump Flags", func () {
+ // ShowDebugValues()
+ log.ShowFlags()
+ for s, wg := range myLogGui.groups {
+ log.Info("Dump Flags", s)
+ for _, f := range wg.flags {
+ log.Info("Dump Flags\t", f.Get(), f.Name, ":", f.Desc)
+ }
+ }
+ })
+
+ d.flagG = d.win.Box().NewGroup("Subsystem (aka package)")
+ d.flagG = d.flagG.NewBox("bw vbox", false)
+
+ g.NewButton("Add all Flags", func () {
+ flags := log.ShowFlags()
+ for _, f := range flags {
+ addFlag(d.flagG, f)
+ }
+ })
+
+ g.NewButton("Close", func () {
+ d.Hide()
+ })
+
+ flags := log.ShowFlags()
+ for _, f := range flags {
+ addFlag(d.flagG, f)
+ }
+}
+
+func addFlag(p *gui.Node, newf *log.LogFlag) {
+ var flagWidgets *flagGroup
+ if newf == nil { return }
+ if p == nil { return }
+
+ subsys := newf.GetSubsystem()
+ name := newf.GetName()
+
+ if myLogGui.groups[subsys] == nil {
+ flagWidgets = new(flagGroup)
+ flagWidgets.parent = p
+ flagWidgets.name = subsys
+ flagWidgets.group = p.NewGroup(subsys)
+ flagWidgets.grid = flagWidgets.group.NewGrid("flags grid", 3, 1)
+ myLogGui.groups[subsys] = flagWidgets
+ } else {
+ flagWidgets = myLogGui.groups[subsys]
+ }
+
+ for _, f := range flagWidgets.flags {
+ if f.Name == name {
+ log.Info("addFlag() FOUND FLAG", f)
+ return
+ }
+ }
+ log.Info("addFlag() Adding new flag:", subsys, name)
+ newWidget := gadgets.NewLogFlag(flagWidgets.grid, newf)
+ flagWidgets.flags = append(flagWidgets.flags, newWidget)
+}
+
+type flagGroup struct {
+ name string // should be set to the flag.Subsystem
+
+ parent *gui.Node // where to draw our group
+ group *gui.Node
+ grid *gui.Node
+
+ // the widget for each flag
+ flags []*gadgets.LogFlag
+}
diff --git a/settings.go b/settings.go
new file mode 100644
index 0000000..2bc252a
--- /dev/null
+++ b/settings.go
@@ -0,0 +1,43 @@
+package logsettings
+
+import (
+ "go.wit.com/log"
+ "go.wit.com/gui/gui"
+)
+
+// This initializes the main object
+// You can only have one of these
+func New(p *gui.Node) *LogSettings {
+ if myLogGui != nil {return myLogGui}
+ myLogGui = new(LogSettings)
+ myLogGui.parent = p
+ myLogGui.groups = make(map[string]*flagGroup)
+ myLogGui.ready = true
+ myLogGui.hidden = true
+ return myLogGui
+}
+
+// Returns true if the status is valid
+func (d *LogSettings) Ready() bool {
+ if d == nil {return false}
+ if ! d.parent.Ready() {return false}
+ if (d.win == nil) {
+ d.draw()
+ }
+ return d.ready
+}
+
+func (d *LogSettings) Update() bool {
+ if ! d.Ready() {return false}
+ return true
+}
+
+func (d *LogSettings) ShowFlags() {
+ log.ShowFlags()
+ return
+}
+
+func (d *LogSettings) SetAll(b bool) {
+ log.SetAll(b)
+ return
+}
diff --git a/structs.go b/structs.go
new file mode 100644
index 0000000..0637ac4
--- /dev/null
+++ b/structs.go
@@ -0,0 +1,22 @@
+package logsettings
+
+import (
+ "go.wit.com/gui/gui"
+ "go.wit.com/gui/gadgets"
+)
+
+var myLogGui *LogSettings
+
+type LogSettings struct {
+ ready bool
+ hidden bool
+ err error
+
+ groups map[string]*flagGroup
+
+ parent *gui.Node // where to draw our window
+ win *gadgets.BasicWindow // our window for displaying the log package settings
+
+ buttonG *gui.Node // the group of buttons
+ flagG *gui.Node // the group of all the flag checkbox widgets
+}