diff options
| author | Jeff Carr <[email protected]> | 2024-01-08 20:52:10 -0600 |
|---|---|---|
| committer | Jeff Carr <[email protected]> | 2024-01-08 20:52:10 -0600 |
| commit | 3c2da3f096a5e8aeaa657deb2dc047cc23118c99 (patch) | |
| tree | 9be876900a02aebed4540f5453759ea1f1d5c7ce | |
| parent | 2a9724d7a89733db8c41571a8b5d9d0e1f0d76b3 (diff) | |
use "go.wit.com/log"
Signed-off-by: Jeff Carr <[email protected]>
| -rw-r--r-- | gocui/Makefile | 11 | ||||
| -rw-r--r-- | gocui/add.go | 9 | ||||
| -rw-r--r-- | gocui/args.go | 32 | ||||
| -rw-r--r-- | gocui/click.go | 53 | ||||
| -rw-r--r-- | gocui/color.go | 12 | ||||
| -rw-r--r-- | gocui/debug.go | 11 | ||||
| -rw-r--r-- | gocui/gocui.go | 16 | ||||
| -rw-r--r-- | gocui/keybindings.go | 20 | ||||
| -rw-r--r-- | gocui/main.go | 39 | ||||
| -rw-r--r-- | gocui/mouse.go | 30 | ||||
| -rw-r--r-- | gocui/place.go | 24 | ||||
| -rw-r--r-- | gocui/plugin.go | 35 | ||||
| -rw-r--r-- | gocui/showStdout.go | 14 | ||||
| -rw-r--r-- | gocui/structs.go | 6 | ||||
| -rw-r--r-- | gocui/tab.go | 6 | ||||
| -rw-r--r-- | gocui/view.go | 46 | ||||
| -rw-r--r-- | gocui/widget.go | 4 | ||||
| -rw-r--r-- | log.go (renamed from gocui/log.go) | 0 | ||||
| -rw-r--r-- | nocui/args.go | 2 | ||||
| -rw-r--r-- | nocui/go.mod | 10 | ||||
| -rw-r--r-- | nocui/go.sum | 6 |
21 files changed, 230 insertions, 156 deletions
diff --git a/gocui/Makefile b/gocui/Makefile index 4f2a6ee..4c24c14 100644 --- a/gocui/Makefile +++ b/gocui/Makefile @@ -13,3 +13,14 @@ objdump: log: reset tail -f /tmp/witgui.* /tmp/guilogfile + +cleanbuild: + go build -v -x -buildmode=plugin -o ../nocui.so + +check-git-clean: + @git diff-index --quiet HEAD -- || (echo "Git repository is dirty, please commit your changes first"; exit 1) + +redomod: + rm -f go.* + GO111MODULE= go mod init + GO111MODULE= go mod tidy diff --git a/gocui/add.go b/gocui/add.go index 92a512c..c17a3e9 100644 --- a/gocui/add.go +++ b/gocui/add.go @@ -1,6 +1,7 @@ package main import ( + log "go.wit.com/log" "go.wit.com/gui/widget" ) @@ -19,7 +20,7 @@ func (n *node) setFake() { fakeStartHeight = me.TabH fakeStartWidth += me.FakeW } - if (logInfo) { + if (true) { n.showView() } } @@ -27,10 +28,10 @@ func (n *node) setFake() { // set the widget start width & height func (n *node) addWidget() { nw := n.tk - log(logInfo, "setStartWH() w.id =", n.WidgetId, "n.name", n.Name) + log.Log(INFO, "setStartWH() w.id =", n.WidgetId, "n.name", n.Name) switch n.WidgetType { case widget.Root: - log(logInfo, "setStartWH() rootNode w.id =", n.WidgetId, "w.name", n.Name) + log.Log(INFO, "setStartWH() rootNode w.id =", n.WidgetId, "w.name", n.Name) nw.color = &colorRoot n.setFake() return @@ -74,5 +75,5 @@ func (n *node) addWidget() { } */ } - n.showWidgetPlacement(logInfo, "addWidget()") + n.showWidgetPlacement(true, "addWidget()") } diff --git a/gocui/args.go b/gocui/args.go new file mode 100644 index 0000000..5ee05c4 --- /dev/null +++ b/gocui/args.go @@ -0,0 +1,32 @@ +package main + +/* + this enables command line options from other packages like 'gui' and 'log' +*/ + +import ( + log "go.wit.com/log" +) + +var outputS []string + +var NOW log.LogFlag +var INFO log.LogFlag + +var SPEW log.LogFlag +var WARN log.LogFlag + +var ERROR log.LogFlag + +func init() { + full := "toolkit/nocui" + short := "nocui" + + NOW.NewFlag( "NOW", true, full, short, "temp debugging stuff") + INFO.NewFlag("INFO", false, full, short, "normal debugging stuff") + + WARN.NewFlag("WARN", true, full, short, "bad things") + SPEW.NewFlag("SPEW", false, full, short, "spew stuff") + + ERROR.NewFlag("ERROR", false, full, short, "toolkit errors") +} diff --git a/gocui/click.go b/gocui/click.go index 826ca6b..60c2067 100644 --- a/gocui/click.go +++ b/gocui/click.go @@ -3,6 +3,7 @@ package main import ( "fmt" "github.com/awesome-gocui/gocui" + "go.wit.com/log" "go.wit.com/gui/widget" ) @@ -25,7 +26,7 @@ func unsetCurrent(n *node) { // of the current widgets if that widget is supposed // to be in current display func (n *node) updateCurrent() { - log(true, "updateCurrent()", n.Name) + log.Log(NOW, "updateCurrent()", n.Name) if n.WidgetType == widget.Tab { if n.IsCurrent() { // n.tk.color = &colorActiveT @@ -83,18 +84,18 @@ func setCurrentTab(n *node) { w.isCurrent = true p := n.parent.tk p.isCurrent = true - log(true, "setCurrent()", n.Name) + log.Log(NOW, "setCurrent()", n.Name) } func (n *node) doWidgetClick() { switch n.WidgetType { case widget.Root: // THIS IS THE BEGINING OF THE LAYOUT - log(true, "doWidgetClick()", n.Name) + log.Log(NOW, "doWidgetClick()", n.Name) redoWindows(0,0) case widget.Flag: - log(true, "doWidgetClick() FLAG widget name =", n.Name) - log(true, "doWidgetClick() if this is the dropdown menu, handle it here?") + log.Log(NOW, "doWidgetClick() FLAG widget name =", n.Name) + log.Log(NOW, "doWidgetClick() if this is the dropdown menu, handle it here?") case widget.Window: if (me.currentWindow == n) { return @@ -111,7 +112,7 @@ func (n *node) doWidgetClick() { n.redoTabs(me.TabW, me.TabH) for _, child := range n.children { if (child.currentTab == true) { - log(true, "FOUND CURRENT TAB", child.Name) + log.Log(NOW, "FOUND CURRENT TAB", child.Name) setCurrentTab(child) child.placeWidgets(me.RawW, me.RawH) child.showWidgets() @@ -166,16 +167,16 @@ func (n *node) doWidgetClick() { case widget.Box: // w.showWidgetPlacement(logNow, "drawTree()") if (n.horizontal) { - log(true, "BOX IS HORIZONTAL", n.Name) + log.Log(NOW, "BOX IS HORIZONTAL", n.Name) } else { - log(true, "BOX IS VERTICAL", n.Name) + log.Log(NOW, "BOX IS VERTICAL", n.Name) } // n.placeWidgets() n.toggleTree() case widget.Button: n.doUserEvent() case widget.Dropdown: - log(true, "do the dropdown here") + log.Log(NOW, "do the dropdown here") if (me.ddview == nil) { me.ddview = addDropdown() tk := me.ddview.tk @@ -198,7 +199,7 @@ func (n *node) doWidgetClick() { me.ddview.SetVisible(true) return } - log(true, "doWidgetClick() visible =", me.ddview.Visible()) + log.Log(NOW, "doWidgetClick() visible =", me.ddview.Visible()) if (me.ddview.Visible()) { me.ddview.SetVisible(false) me.baseGui.DeleteView("ddview") @@ -206,17 +207,17 @@ func (n *node) doWidgetClick() { } else { var dnsList string for i, s := range n.vals { - log(logNow, "AddText()", n.Name, i, s) + log.Log(NOW, "AddText()", n.Name, i, s) dnsList += s + "\n" } me.ddNode = n - log(logNow, "new dns list should be set to:", dnsList) + log.Log(NOW, "new dns list should be set to:", dnsList) me.ddview.Text = dnsList me.ddview.SetText(dnsList) me.ddview.SetVisible(true) } for i, s := range n.vals { - log(logNow, "AddText()", n.Name, i, s) + log.Log(NOW, "AddText()", n.Name, i, s) } default: } @@ -240,7 +241,7 @@ func (n *node) drawTree(draw bool) { if (w == nil) { return } - n.showWidgetPlacement(logNow, "drawTree()") + n.showWidgetPlacement(true, "drawTree()") if (draw) { // w.textResize() n.showView() @@ -257,27 +258,27 @@ func click(g *gocui.Gui, v *gocui.View) error { // var l string // var err error - log(logVerbose, "click() START", v.Name()) + log.Log(INFO, "click() START", v.Name()) // n := me.rootNode.findWidgetName(v.Name()) n := findUnderMouse() if (n != nil) { - log(logNow, "click() Found widget =", n.WidgetId, n.Name, ",", n.Text) + log.Log(NOW, "click() Found widget =", n.WidgetId, n.Name, ",", n.Text) if (n.Name == "DropBox") { - log(logNow, "click() this is the dropdown menu. set a flag here what did I click? where is the mouse?") - log(logNow, "click() set a global dropdown clicked flag=true here") + log.Log(NOW, "click() this is the dropdown menu. set a flag here what did I click? where is the mouse?") + log.Log(NOW, "click() set a global dropdown clicked flag=true here") me.ddClicked = true } n.doWidgetClick() } else { - log(logNow, "click() could not find node name =", v.Name()) + log.Log(NOW, "click() could not find node name =", v.Name()) } if _, err := g.SetCurrentView(v.Name()); err != nil { - log(logNow, "click() END err =", err) + log.Log(NOW, "click() END err =", err) return err } - log(logVerbose, "click() END") + log.Log(NOW, "click() END") return nil } @@ -299,14 +300,14 @@ func findUnderMouse() *node { } } if (n == me.ddview) { - log(true, "findUnderMouse() found ddview") + log.Log(NOW, "findUnderMouse() found ddview") if n.Visible() { - log(true, "findUnderMouse() and ddview is visable. hide it here. TODO: find highlighted row") + log.Log(NOW, "findUnderMouse() and ddview is visable. hide it here. TODO: find highlighted row") found = n // find the actual value here and set the dropdown widget me.baseGui.DeleteView("ddview") } else { - log(true, "findUnderMouse() I was lying, actually it's not found") + log.Log(NOW, "findUnderMouse() I was lying, actually it's not found") } } @@ -319,7 +320,7 @@ func findUnderMouse() *node { // TODO: pop up menu with a list of them for _, n := range widgets { //log(logNow, "ctrlDown() FOUND widget", widget.id, widget.name) - n.showWidgetPlacement(logNow, "findUnderMouse() FOUND") + n.showWidgetPlacement(true, "findUnderMouse() FOUND") } return found } @@ -351,6 +352,6 @@ func ctrlDown(g *gocui.Gui, v *gocui.View) error { } else { me.ctrlDown.showView() } - me.ctrlDown.showWidgetPlacement(logNow, "ctrlDown:") + me.ctrlDown.showWidgetPlacement(true, "ctrlDown:") return nil } diff --git a/gocui/color.go b/gocui/color.go index c665bb6..ca4301f 100644 --- a/gocui/color.go +++ b/gocui/color.go @@ -3,6 +3,8 @@ package main import ( "math/rand" "github.com/awesome-gocui/gocui" + + "go.wit.com/log" ) //w.v.SelBgColor = gocui.ColorCyan @@ -73,10 +75,10 @@ func (n *node) setColor(newColor *colorT) { return } if (tk.color == nil) { - log(true, "Set the node to color = nil") + log.Log(NOW, "Set the node to color = nil") tk.color = &colorNone } - log(true, "Set the node to color =", tk.color.name) + log.Log(NOW, "Set the node to color =", tk.color.name) n.recreateView() } @@ -87,7 +89,7 @@ func (n *node) setDefaultWidgetColor() { func (n *node) setDefaultHighlight() { w := n.tk if (w.v == nil) { - log(logError, "SetColor() failed on view == nil") + log.Log(ERROR, "SetColor() failed on view == nil") return } w.v.SelBgColor = gocui.ColorGreen @@ -97,7 +99,7 @@ func (n *node) setDefaultHighlight() { func randColor() gocui.Attribute { colors := []string{"Green", "#FFAA55", "Yellow", "Blue", "Red", "Black", "White"} i := rand.Intn(len(colors)) - log(true, "randColor() i =", i) + log.Log(NOW, "randColor() i =", i) return gocui.GetColor(colors[i]) } @@ -107,7 +109,7 @@ func (n *node) redoColor(draw bool) { return } - sleep(.05) + log.Sleep(.05) n.setDefaultHighlight() n.setDefaultWidgetColor() diff --git a/gocui/debug.go b/gocui/debug.go index 9d41d90..8c70dd3 100644 --- a/gocui/debug.go +++ b/gocui/debug.go @@ -2,6 +2,7 @@ package main import ( "fmt" + "go.wit.com/log" "go.wit.com/gui/widget" ) @@ -10,7 +11,7 @@ func (n *node) dumpTree(draw bool) { if (w == nil) { return } - n.showWidgetPlacement(logNow, "dumpTree()") + n.showWidgetPlacement(true, "dumpTree()") for _, child := range n.children { child.dumpTree(draw) @@ -19,7 +20,7 @@ func (n *node) dumpTree(draw bool) { func (n *node) showWidgetPlacement(b bool, s string) { if (n == nil) { - log(logError, "WTF w == nil") + log.Log(ERROR, "WTF w == nil") return } w := n.tk @@ -27,7 +28,7 @@ func (n *node) showWidgetPlacement(b bool, s string) { var s1 string var pId int if (n.parent == nil) { - log(logVerbose, "showWidgetPlacement() parent == nil", n.WidgetId, w.cuiName) + log.Log(INFO, "showWidgetPlacement() parent == nil", n.WidgetId, w.cuiName) pId = 0 } else { pId = n.parent.WidgetId @@ -46,11 +47,11 @@ func (n *node) showWidgetPlacement(b bool, s string) { } } tmp := "." + n.Name + "." - log(b, s1, s, n.WidgetType, ",", tmp) // , "text=", w.text) + log.Log(INFO, s1, s, n.WidgetType, ",", tmp) // , "text=", w.text) } func (n *node) dumpWidget(pad string) { - log(true, "node:", pad, n.WidgetId, "At(", n.AtW, n.AtH, ") ,", n.WidgetType, ", n.Name =", n.Name, ", n.Text =", n.Text) + log.Log(NOW, "node:", pad, n.WidgetId, "At(", n.AtW, n.AtH, ") ,", n.WidgetType, ", n.Name =", n.Name, ", n.Text =", n.Text) } func (n *node) listWidgets() { diff --git a/gocui/gocui.go b/gocui/gocui.go index d2877d7..1c2e8f7 100644 --- a/gocui/gocui.go +++ b/gocui/gocui.go @@ -7,6 +7,8 @@ package main import ( "errors" "github.com/awesome-gocui/gocui" + + "go.wit.com/log" ) // This initializes the gocui package @@ -47,21 +49,21 @@ func gocuiMain() { func gocuiEvent(g *gocui.Gui) error { maxX, maxY := g.Size() mx, my := g.MousePosition() - log(logVerbose, "handleEvent() START", maxX, maxY, mx, my, msgMouseDown) + log.Log(NOW, "handleEvent() START", maxX, maxY, mx, my, msgMouseDown) if _, err := g.View("msg"); msgMouseDown && err == nil { moveMsg(g) } if widgetView, _ := g.View("msg"); widgetView == nil { - log(logNow, "handleEvent() create output widget now", maxX, maxY, mx, my) + log.Log(NOW, "handleEvent() create output widget now", maxX, maxY, mx, my) makeOutputWidget(g, "this is a create before a mouse click") if (me.logStdout != nil) { // setOutput(me.logStdout) } } else { - log(logInfo, "output widget already exists", maxX, maxY, mx, my) + log.Log(INFO, "output widget already exists", maxX, maxY, mx, my) } mouseMove(g) - log(logVerbose, "handleEvent() END ", maxX, maxY, mx, my, msgMouseDown) + log.Log(INFO, "handleEvent() END ", maxX, maxY, mx, my, msgMouseDown) return nil } @@ -74,7 +76,7 @@ func setFrame(b bool) { // what is this do? I made it just 2 lines for now. Is this useful for something? v := SetView("global", 5, 10, 5, 10, 0) // x0, x1, y1, y2, overlap if (v == nil) { - log(logError, "setFrame() global failed") + log.Log(ERROR, "setFrame() global failed") } v.Frame = b } @@ -85,14 +87,14 @@ func quit(g *gocui.Gui, v *gocui.View) error { func SetView(name string, x0, y0, x1, y1 int, overlaps byte) *gocui.View { if (me.baseGui == nil) { - log(logError, "SetView() ERROR: me.baseGui == nil") + log.Log(ERROR, "SetView() ERROR: me.baseGui == nil") return nil } v, err := me.baseGui.SetView(name, x0, y0, x1, y1, overlaps) if err != nil { if !errors.Is(err, gocui.ErrUnknownView) { - log(logError, "SetView() global failed on name =", name) + log.Log(ERROR, "SetView() global failed on name =", name) } return nil } diff --git a/gocui/keybindings.go b/gocui/keybindings.go index 3e6f1a1..4599cf3 100644 --- a/gocui/keybindings.go +++ b/gocui/keybindings.go @@ -5,8 +5,9 @@ package main import ( - "os" "github.com/awesome-gocui/gocui" + + "go.wit.com/log" "go.wit.com/gui/widget" ) @@ -117,12 +118,13 @@ func addDebugKeys(g *gocui.Gui) { // log to output window g.SetKeybinding("", 'o', gocui.ModNone, func(g *gocui.Gui, v *gocui.View) error { + log.Log(ERROR, "TODO: re-implement this") if me.logStdout.Visible() { me.logStdout.SetVisible(false) - setOutput(os.Stdout) + // setOutput(os.Stdout) } else { me.logStdout.SetVisible(true) - setOutput(me.logStdout.tk) + // setOutput(me.logStdout.tk) } return nil }) @@ -145,23 +147,11 @@ func addDebugKeys(g *gocui.Gui) { a.B = true a.ActionType = widget.EnableDebug callback <- a - logInfo = true - logVerbose = true - } else { - logInfo = false - logVerbose = false } return nil }) g.SetKeybinding("", gocui.KeyCtrlV, gocui.ModNone, func(g *gocui.Gui, v *gocui.View) error { - if (logVerbose) { - logInfo = false - logVerbose = false - } else { - logInfo = true - logVerbose = true - } return nil }) diff --git a/gocui/main.go b/gocui/main.go index 5157ecd..8c079c9 100644 --- a/gocui/main.go +++ b/gocui/main.go @@ -6,24 +6,26 @@ package main import ( "os" + + "go.wit.com/log" "go.wit.com/gui/widget" ) // sets defaults and establishes communication // to this toolkit from the wit/gui golang package func init() { - log(logInfo, "Init() of awesome-gocui") + log.Log(INFO, "Init() of awesome-gocui") // init the config struct default values Set(&me, "default") pluginChan = make(chan widget.Action) - log(logNow, "Init() start pluginChan") + log.Log(NOW, "Init() start pluginChan") go catchActionChannel() - sleep(.1) // probably not needed, but in here for now under development + log.Sleep(.1) // probably not needed, but in here for now under development go main() - sleep(.1) // probably not needed, but in here for now under development + log.Sleep(.1) // probably not needed, but in here for now under development } /* @@ -33,17 +35,17 @@ recieves requests from the program to do things like: * etc.. */ func catchActionChannel() { - log(logInfo, "catchActionChannel() START") + log.Log(INFO, "catchActionChannel() START") for { - log(logInfo, "catchActionChannel() infinite for() loop restarted select on channel") + log.Log(INFO, "catchActionChannel() infinite for() loop restarted select on channel") select { case a := <-pluginChan: if (me.baseGui == nil) { // something went wrong initializing the gocui - log(logError,"ERROR: console did not initialize") + log.Log(ERROR, "ERROR: console did not initialize") continue } - log(logInfo, "catchActionChannel()", a.WidgetId, a.ActionType, a.WidgetType, a.Name) + log.Log(INFO, "catchActionChannel()", a.WidgetId, a.ActionType, a.WidgetType, a.Name) action(&a) } } @@ -51,23 +53,23 @@ func catchActionChannel() { func Exit() { // TODO: what should actually happen here? - log(true, "Exit() here. doing standardExit()") + log.Log(NOW, "Exit() here. doing standardExit()") standardExit() } func standardExit() { - log(true, "standardExit() doing baseGui.Close()") + log.Log(NOW, "standardExit() doing baseGui.Close()") me.baseGui.Close() - log(true, "standardExit() doing outf.Close()") + log.Log(NOW, "standardExit() doing outf.Close()") outf.Close() // log(true, "standardExit() setOutput(os.Stdout)") // setOutput(os.Stdout) - log(true, "standardExit() send back Quit()") + log.Log(NOW, "standardExit() send back Quit()") go sendBackQuit() // don't stall here in case the // induces a delay in case the callback channel is broken - sleep(1) - log(true, "standardExit() exit()") - exit() + log.Sleep(1) + log.Log(NOW, "standardExit() exit()") + os.Exit(0) } func sendBackQuit() { // send 'Quit' back to the program (?) @@ -80,11 +82,12 @@ var outf *os.File func main() { var err error - log(logInfo, "main() start Init()") + log.Log(INFO, "main() start Init()") outf, err = os.OpenFile("/tmp/witgui.log", os.O_RDWR | os.O_CREATE | os.O_APPEND, 0666) if err != nil { - exit("error opening file: %v", err) + log.Error(err, "error opening file: %v") + os.Exit(0) } os.Stdout = outf defer outf.Close() @@ -96,6 +99,6 @@ func main() { os.Stderr = ferr gocuiMain() - log(true, "MouseMain() closed") + log.Log(NOW, "MouseMain() closed") standardExit() } diff --git a/gocui/mouse.go b/gocui/mouse.go index 50c2834..9b1096d 100644 --- a/gocui/mouse.go +++ b/gocui/mouse.go @@ -8,6 +8,8 @@ import ( "errors" "fmt" "github.com/awesome-gocui/gocui" + + "go.wit.com/log" ) // this function uses the mouse position to highlight & unhighlight things @@ -24,7 +26,7 @@ func mouseMove(g *gocui.Gui) { func msgDown(g *gocui.Gui, v *gocui.View) error { initialMouseX, initialMouseY = g.MousePosition() - log(true, "msgDown() X,Y", initialMouseX, initialMouseY) + log.Log(NOW, "msgDown() X,Y", initialMouseX, initialMouseY) if vx, vy, _, _, err := g.ViewPosition("msg"); err == nil { xOffset = initialMouseX - vx yOffset = initialMouseY - vy @@ -35,7 +37,7 @@ func msgDown(g *gocui.Gui, v *gocui.View) error { func hideDDview() error { w, h := me.baseGui.MousePosition() - log(true, "hide dropdown menu() view msgMouseDown (w,h) =", w, h) + log.Log(NOW, "hide dropdown menu() view msgMouseDown (w,h) =", w, h) if (me.ddview == nil) { return gocui.ErrUnknownView } @@ -48,7 +50,7 @@ func hideDDview() error { func showDDview() error { w, h := me.baseGui.MousePosition() - log(true, "show dropdown menu() view msgMouseDown (w,h) =", w, h) + log.Log(NOW, "show dropdown menu() view msgMouseDown (w,h) =", w, h) if (me.ddview == nil) { return gocui.ErrUnknownView } @@ -61,23 +63,23 @@ func showDDview() error { func mouseUp(g *gocui.Gui, v *gocui.View) error { w, h := g.MousePosition() - log(true, "mouseUp() view msgMouseDown (check here for dropdown menu click) (w,h) =", w, h) + log.Log(NOW, "mouseUp() view msgMouseDown (check here for dropdown menu click) (w,h) =", w, h) if (me.ddClicked) { me.ddClicked = false - log(true, "mouseUp() ddview is the thing that was clicked", w, h) - log(true, "mouseUp() find out what the string is here", w, h, me.ddview.tk.gocuiSize.h1) + log.Log(NOW, "mouseUp() ddview is the thing that was clicked", w, h) + log.Log(NOW, "mouseUp() find out what the string is here", w, h, me.ddview.tk.gocuiSize.h1) var newZone string = "" if (me.ddNode != nil) { value := h - me.ddview.tk.gocuiSize.h0 - 1 - log(true, "mouseUp() me.ddview.tk.gocuiSize.h1 =", me.ddview.tk.gocuiSize.h1) - log(true, "mouseUp() me.ddNode.vals =", me.ddNode.vals) + log.Log(NOW, "mouseUp() me.ddview.tk.gocuiSize.h1 =", me.ddview.tk.gocuiSize.h1) + log.Log(NOW, "mouseUp() me.ddNode.vals =", me.ddNode.vals) valsLen := len(me.ddNode.vals) - log(true, "mouseUp() value =", value, "valsLen =", valsLen) - log(true, "mouseUp() me.ddNode.vals =", me.ddNode.vals) + log.Log(NOW, "mouseUp() value =", value, "valsLen =", valsLen) + log.Log(NOW, "mouseUp() me.ddNode.vals =", me.ddNode.vals) if ((value >= 0) && (value < valsLen)) { newZone = me.ddNode.vals[value] - log(true, "mouseUp() value =", value, "newZone =", newZone) + log.Log(NOW, "mouseUp() value =", value, "newZone =", newZone) } } hideDDview() @@ -124,10 +126,10 @@ func mouseDown(g *gocui.Gui, v *gocui.View) error { msg := fmt.Sprintf("Mouse really down at: %d,%d", mx, my) + "foobar" if (test == me.ddview) { if (me.ddview.Visible()) { - log(true, "hide DDview() Mouse really down at:", mx, my) + log.Log(NOW, "hide DDview() Mouse really down at:", mx, my) hideDDview() } else { - log(true, "show DDview() Mouse really down at:", mx, my) + log.Log(NOW, "show DDview() Mouse really down at:", mx, my) showDDview() } return nil @@ -138,7 +140,7 @@ func mouseDown(g *gocui.Gui, v *gocui.View) error { } else if x+len(msg)+1 > maxX-1 { x = maxX - 1 - len(msg) - 1 } - log(true, "mouseDown() about to write out message to 'globalDown' view. msg =", msg) + log.Log(NOW, "mouseDown() about to write out message to 'globalDown' view. msg =", msg) if v, err := g.SetView("globalDown", x, my-1, x+len(msg)+1, my+1, 0); err != nil { if !errors.Is(err, gocui.ErrUnknownView) { return err diff --git a/gocui/place.go b/gocui/place.go index f4b5edd..80b03ca 100644 --- a/gocui/place.go +++ b/gocui/place.go @@ -2,6 +2,8 @@ package main import ( "strings" + + "go.wit.com/log" "go.wit.com/gui/widget" ) @@ -9,7 +11,7 @@ func (n *node) placeBox(startW int, startH int) { if (n.WidgetType != widget.Box) { return } - n.showWidgetPlacement(logNow, "boxS()") + n.showWidgetPlacement(true, "boxS()") newW := startW newH := startH @@ -20,11 +22,11 @@ func (n *node) placeBox(startW int, startH int) { w := newR.w1 - newR.w0 h := newR.h1 - newR.h0 if (n.horizontal) { - log(logNow, "BOX IS HORIZONTAL", n.Name, "newWH()", newW, newH, "child()", w, h, child.Name) + log.Log(NOW, "BOX IS HORIZONTAL", n.Name, "newWH()", newW, newH, "child()", w, h, child.Name) // expand based on the child width newW += w } else { - log(logNow, "BOX IS VERTICAL ", n.Name, "newWH()", newW, newH, "child()", w, h, child.Name) + log.Log(NOW, "BOX IS VERTICAL ", n.Name, "newWH()", newW, newH, "child()", w, h, child.Name) // expand based on the child height newH += h } @@ -33,7 +35,7 @@ func (n *node) placeBox(startW int, startH int) { // just compute this every time? // newR := n.realGocuiSize() - n.showWidgetPlacement(logNow, "boxE()") + n.showWidgetPlacement(true, "boxE()") } func (n *node) placeWidgets(startW int, startH int) { @@ -62,7 +64,7 @@ func (n *node) placeWidgets(startW int, startH int) { case widget.Group: // move the group to the parent's next location n.gocuiSetWH(startW, startH) - n.showWidgetPlacement(logNow, "group()") + n.showWidgetPlacement(true, "group()") newW := startW + me.GroupPadW newH := startH + 3 // normal hight of the group label @@ -84,7 +86,7 @@ func (n *node) placeWidgets(startW int, startH int) { func (n *node) placeGrid(startW int, startH int) { w := n.tk - n.showWidgetPlacement(logInfo, "grid0:") + n.showWidgetPlacement(true, "grid0:") if (n.WidgetType != widget.Grid) { return } @@ -103,12 +105,12 @@ func (n *node) placeGrid(startW int, startH int) { w.heights[child.AtH] = childH } // child.showWidgetPlacement(logInfo, "grid: ") - log(logVerbose, "placeGrid:", child.Name, "child()", childW, childH, "At()", child.AtW, child.AtH) + log.Log(INFO, "placeGrid:", child.Name, "child()", childW, childH, "At()", child.AtW, child.AtH) } // find the width and height offset of the grid for AtW,AtH for _, child := range n.children { - child.showWidgetPlacement(logInfo, "grid1:") + child.showWidgetPlacement(true, "grid1:") var totalW, totalH int for i, w := range w.widths { @@ -126,11 +128,11 @@ func (n *node) placeGrid(startW int, startH int) { newW := startW + totalW newH := startH + totalH - log(logVerbose, "placeGrid:", child.Name, "new()", newW, newH, "At()", child.AtW, child.AtH) + log.Log(INFO, "placeGrid:", child.Name, "new()", newW, newH, "At()", child.AtW, child.AtH) child.placeWidgets(newW, newH) - child.showWidgetPlacement(logInfo, "grid2:") + child.showWidgetPlacement(true, "grid2:") } - n.showWidgetPlacement(logInfo, "grid3:") + n.showWidgetPlacement(true, "grid3:") } // computes the real, actual size of all the gocli objects in a widget diff --git a/gocui/plugin.go b/gocui/plugin.go index d66e8f6..2055529 100644 --- a/gocui/plugin.go +++ b/gocui/plugin.go @@ -3,11 +3,12 @@ package main import ( // if you include more than just this import // then your plugin might be doing something un-ideal (just a guess from 2023/02/27) + "go.wit.com/log" "go.wit.com/gui/widget" ) func action(a *widget.Action) { - log(logInfo, "action() START", a.WidgetId, a.ActionType, a.WidgetType, a.Name) + log.Log(INFO, "action() START", a.WidgetId, a.ActionType, a.WidgetType, a.Name) n := me.rootNode.findWidgetId(a.WidgetId) var w *guiWidget if (n != nil) { @@ -22,7 +23,7 @@ func action(a *widget.Action) { } else { // this is done to protect the plugin being 'refreshed' with the // widget binary tree. TODO: find a way to keep them in sync - log(logError, "action() Add ignored for already defined widget", + log.Log(ERROR, "action() Add ignored for already defined widget", a.WidgetId, a.ActionType, a.WidgetType, a.Name) } case widget.Show: @@ -33,12 +34,12 @@ func action(a *widget.Action) { } case widget.Set: if a.WidgetType == widget.Flag { - log(logNow, "TODO: set flag here", a.ActionType, a.WidgetType, a.Name) - log(logNow, "TODO: n.WidgetType =", n.WidgetType, "n.Name =", a.Name) + log.Log(NOW, "TODO: set flag here", a.ActionType, a.WidgetType, a.Name) + log.Log(NOW, "TODO: n.WidgetType =", n.WidgetType, "n.Name =", a.Name) } else { if (a.A == nil) { - log(logError, "TODO: Set here. a == nil id =", a.WidgetId, "type =", a.WidgetType, "Name =", a.Name) - log(logError, "TODO: Set here. id =", a.WidgetId, "n.Name =", n.Name) + log.Log(ERROR, "TODO: Set here. a == nil id =", a.WidgetId, "type =", a.WidgetType, "Name =", a.Name) + log.Log(ERROR, "TODO: Set here. id =", a.WidgetId, "n.Name =", n.Name) } else { n.Set(a.A) } @@ -48,38 +49,38 @@ func action(a *widget.Action) { case widget.AddText: n.AddText(a.S) case widget.Move: - log(logNow, "attempt to move() =", a.ActionType, a.WidgetType, a.Name) + log.Log(NOW, "attempt to move() =", a.ActionType, a.WidgetType, a.Name) case widget.CloseToolkit: - log(logNow, "attempting to close the plugin and release stdout and stderr") + log.Log(NOW, "attempting to close the plugin and release stdout and stderr") standardExit() case widget.Enable: if n.Visible() { // widget was already shown } else { - log(logInfo, "Setting Visable to true", a.Name) + log.Log(INFO, "Setting Visable to true", a.Name) n.SetVisible(true) } case widget.Disable: if n.Visible() { - log(logInfo, "Setting Visable to false", a.Name) + log.Log(INFO, "Setting Visable to false", a.Name) n.SetVisible(false) } else { // widget was already hidden } default: - log(logError, "action() ActionType =", a.ActionType, "WidgetType =", a.WidgetType, "Name =", a.Name) + log.Log(ERROR, "action() ActionType =", a.ActionType, "WidgetType =", a.WidgetType, "Name =", a.Name) } - log(logInfo, "action() END") + log.Log(INFO, "action() END") } func (n *node) AddText(text string) { if (n == nil) { - log(logNow, "widget is nil") + log.Log(NOW, "widget is nil") return } n.vals = append(n.vals, text) for i, s := range n.vals { - log(logNow, "AddText()", n.Name, i, s) + log.Log(NOW, "AddText()", n.Name, i, s) } n.SetText(text) } @@ -87,7 +88,7 @@ func (n *node) AddText(text string) { func (n *node) SetText(text string) { var changed bool = false if (n == nil) { - log(logNow, "widget is nil") + log.Log(NOW, "widget is nil") return } if (n.Text != text) { @@ -111,7 +112,7 @@ func (n *node) SetText(text string) { func (n *node) Set(val any) { // w := n.tk - log(logInfo, "Set() value =", val) + log.Log(INFO, "Set() value =", val) switch v := val.(type) { case bool: @@ -122,6 +123,6 @@ func (n *node) Set(val any) { case int: n.I = val.(int) default: - log(logError, "Set() unknown type =", val, v) + log.Log(ERROR, "Set() unknown type =", val, v) } } diff --git a/gocui/showStdout.go b/gocui/showStdout.go index 5887527..bcbffc9 100644 --- a/gocui/showStdout.go +++ b/gocui/showStdout.go @@ -5,6 +5,8 @@ import ( "fmt" "github.com/awesome-gocui/gocui" + + "go.wit.com/log" "go.wit.com/gui/widget" ) @@ -24,7 +26,7 @@ func showMsg(g *gocui.Gui, v *gocui.View) error { var l string var err error - log(true, "showMsg() v.name =", v.Name()) + log.Log(NOW, "showMsg() v.name =", v.Name()) if _, err := g.SetCurrentView(v.Name()); err != nil { return err } @@ -62,9 +64,9 @@ func makeOutputWidget(g *gocui.Gui, stringFromMouseClick string) *gocui.View { } v, err := g.View("msg") if (v == nil) { - log(true, "makeoutputwindow() this is supposed to happen. v == nil", err) + log.Log(NOW, "makeoutputwindow() this is supposed to happen. v == nil", err) } else { - log(true, "makeoutputwindow() msg != nil. WTF now? err =", err) + log.Log(NOW, "makeoutputwindow() msg != nil. WTF now? err =", err) } // help, err := g.SetView("help", maxX-32, 0, maxX-1, 13, 0) @@ -72,16 +74,16 @@ func makeOutputWidget(g *gocui.Gui, stringFromMouseClick string) *gocui.View { v, err = g.SetView("msg", maxX-32, maxY/2, maxX/2+outputW, maxY/2+outputH, 0) if errors.Is(err, gocui.ErrUnknownView) { - log(true, "makeoutputwindow() this is supposed to happen?", err) + log.Log(NOW, "makeoutputwindow() this is supposed to happen?", err) } if (err != nil) { - log(true, "makeoutputwindow() create output window failed", err) + log.Log(NOW, "makeoutputwindow() create output window failed", err) return nil } if (v == nil) { - log(true, "makeoutputwindow() msg == nil. WTF now? err =", err) + log.Log(NOW, "makeoutputwindow() msg == nil. WTF now? err =", err) return nil } else { me.logStdout.tk.v = v diff --git a/gocui/structs.go b/gocui/structs.go index d1fe381..5a8830a 100644 --- a/gocui/structs.go +++ b/gocui/structs.go @@ -15,6 +15,8 @@ import ( "sync" "strings" "github.com/awesome-gocui/gocui" + + "go.wit.com/log" ) // It's probably a terrible idea to call this 'me' @@ -181,7 +183,7 @@ func (w *guiWidget) Write(p []byte) (n int, err error) { func Set(ptr interface{}, tag string) error { if reflect.TypeOf(ptr).Kind() != reflect.Ptr { - log(logError, "Set() Not a pointer", ptr, "with tag =", tag) + log.Log(ERROR, "Set() Not a pointer", ptr, "with tag =", tag) return fmt.Errorf("Not a pointer") } @@ -203,7 +205,7 @@ func setField(field reflect.Value, defaultVal string, name string) error { // log("setField() Can't set value", field, defaultVal) return fmt.Errorf("Can't set value\n") } else { - log(true, "setField() Can set value", name, defaultVal) + log.Log(NOW, "setField() Can set value", name, defaultVal) } switch field.Kind() { diff --git a/gocui/tab.go b/gocui/tab.go index 382438c..f3a6ef2 100644 --- a/gocui/tab.go +++ b/gocui/tab.go @@ -4,6 +4,8 @@ package main import ( "strings" + + "go.wit.com/log" "go.wit.com/gui/widget" ) @@ -76,7 +78,7 @@ func redoWindows(nextW int, nextH int) { sizeW := w.Width() + me.WindowPadW sizeH := w.Height() nextW += sizeW - log(logNow, "redoWindows() start nextW,H =", nextW, nextH, "gocuiSize.W,H =", sizeW, sizeH, n.Name) + log.Log(NOW, "redoWindows() start nextW,H =", nextW, nextH, "gocuiSize.W,H =", sizeW, sizeH, n.Name) if n.hasTabs { n.redoTabs(me.TabW, me.TabH) @@ -103,7 +105,7 @@ func (p *node) redoTabs(nextW int, nextH int) { sizeW := w.Width() + me.TabPadW sizeH := w.Height() - log(logNow, "redoTabs() start nextW,H =", nextW, nextH, "gocuiSize.W,H =", sizeW, sizeH, n.Name) + log.Log(NOW, "redoTabs() start nextW,H =", nextW, nextH, "gocuiSize.W,H =", sizeW, sizeH, n.Name) nextW += sizeW } } diff --git a/gocui/view.go b/gocui/view.go index a93ac28..aff8381 100644 --- a/gocui/view.go +++ b/gocui/view.go @@ -8,6 +8,8 @@ import ( "strings" "github.com/awesome-gocui/gocui" + + "go.wit.com/log" "go.wit.com/gui/widget" ) @@ -26,7 +28,7 @@ func (n *node) textResize() bool { var changed bool = false for i, s := range splitLines(n.Text) { - log(logInfo, "textResize() len =", len(s), i, s) + log.Log(INFO, "textResize() len =", len(s), i, s) if (width < len(s)) { width = len(s) } @@ -41,7 +43,7 @@ func (n *node) textResize() bool { changed = true } if (changed) { - n.showWidgetPlacement(logNow, "textResize() changed") + n.showWidgetPlacement(true, "textResize() changed") } return changed } @@ -57,7 +59,7 @@ func (n *node) showView() { w := n.tk if (w.cuiName == "") { - log(logError, "showView() w.cuiName was not set for widget", w) + log.Log(ERROR, "showView() w.cuiName was not set for widget", w) w.cuiName = strconv.Itoa(n.WidgetId) } @@ -66,15 +68,15 @@ func (n *node) showView() { n.recreateView() } x0, y0, x1, y1, err := me.baseGui.ViewPosition(w.cuiName) - log(logInfo, "showView() w.v already defined for widget", n.Name, err) + log.Log(INFO, "showView() w.v already defined for widget", n.Name, err) // n.smartGocuiSize() changed := n.textResize() if (changed) { - log(logNow, "showView() textResize() changed. Should recreateView here wId =", w.cuiName) + log.Log(NOW, "showView() textResize() changed. Should recreateView here wId =", w.cuiName) } else { - log(logNow, "showView() Clear() and Fprint() here wId =", w.cuiName) + log.Log(NOW, "showView() Clear() and Fprint() here wId =", w.cuiName) w.v.Clear() fmt.Fprint(w.v, n.Text) n.SetVisible(false) @@ -89,17 +91,17 @@ func (n *node) showView() { return } if (y0 != w.gocuiSize.h0) { - log(logError, "showView() start hight mismatch id=", w.cuiName, "gocui h vs computed h =", w.gocuiSize.h0, y0) + log.Log(ERROR, "showView() start hight mismatch id=", w.cuiName, "gocui h vs computed h =", w.gocuiSize.h0, y0) n.recreateView() return } if (x1 != w.gocuiSize.w1) { - log(logError, "showView() too wide", w.cuiName, "w,w", w.gocuiSize.w1, x1) + log.Log(ERROR, "showView() too wide", w.cuiName, "w,w", w.gocuiSize.w1, x1) n.recreateView() return } if (y1 != w.gocuiSize.h1) { - log(logError, "showView() too high", w.cuiName, "h,h", w.gocuiSize.h1, y1) + log.Log(ERROR, "showView() too high", w.cuiName, "h,h", w.gocuiSize.h1, y1) n.recreateView() return } @@ -112,9 +114,9 @@ func (n *node) showView() { func (n *node) recreateView() { var err error w := n.tk - log(logError, "recreateView() START", n.WidgetType, n.Name) + log.Log(ERROR, "recreateView() START", n.WidgetType, n.Name) if (me.baseGui == nil) { - log(logError, "recreateView() ERROR: me.baseGui == nil", w) + log.Log(ERROR, "recreateView() ERROR: me.baseGui == nil", w) return } @@ -123,10 +125,10 @@ func (n *node) recreateView() { w.v = nil if (n.Name == "CLOUDFLARE_EMAIL") { - n.showWidgetPlacement(logNow, "n.Name=" + n.Name + " n.Text=" + n.Text + " " + w.cuiName) + n.showWidgetPlacement(true, "n.Name=" + n.Name + " n.Text=" + n.Text + " " + w.cuiName) n.dumpWidget("jwc") n.textResize() - n.showWidgetPlacement(logNow, "n.Name=" + n.Name + " n.Text=" + n.Text + " " + w.cuiName) + n.showWidgetPlacement(true, "n.Name=" + n.Name + " n.Text=" + n.Text + " " + w.cuiName) } a := w.gocuiSize.w0 @@ -136,13 +138,13 @@ func (n *node) recreateView() { w.v, err = me.baseGui.SetView(w.cuiName, a, b, c, d, 0) if err == nil { - n.showWidgetPlacement(logError, "recreateView()") - log(logError, "recreateView() internal plugin error err = nil") + n.showWidgetPlacement(true, "recreateView()") + log.Log(ERROR, "recreateView() internal plugin error err = nil") return } if !errors.Is(err, gocui.ErrUnknownView) { - n.showWidgetPlacement(logError, "recreateView()") - log(logError, "recreateView() internal plugin error error.IS()", err) + n.showWidgetPlacement(true, "recreateView()") + log.Log(ERROR, "recreateView() internal plugin error error.IS()", err) return } @@ -161,7 +163,7 @@ func (n *node) recreateView() { w.v.Frame = w.frame w.v.Clear() fmt.Fprint(w.v, n.Text) - // n.showWidgetPlacement(logNow, "n.Name=" + n.Name + " n.Text=" + n.Text + " " + w.cuiName) + // n.showWidgetPlacement(true, "n.Name=" + n.Name + " n.Text=" + n.Text + " " + w.cuiName) // n.dumpWidget("jwc 2") // if you don't do this here, it will be black & white only @@ -173,10 +175,10 @@ func (n *node) recreateView() { w.v.SelBgColor = w.color.selBg } if (n.Name == "CLOUDFLARE_EMAIL") { - n.showWidgetPlacement(logNow, "n.Name=" + n.Name + " n.Text=" + n.Text + " " + w.cuiName) + n.showWidgetPlacement(true, "n.Name=" + n.Name + " n.Text=" + n.Text + " " + w.cuiName) n.dumpTree(true) } - log(logError, "recreateView() END") + log.Log(ERROR, "recreateView() END") } func (n *node) hideWidgets() { @@ -210,7 +212,7 @@ func (n *node) showFake() { w := n.tk if (w.isFake) { n.setFake() - n.showWidgetPlacement(logNow, "showFake:") + n.showWidgetPlacement(true, "showFake:") n.showView() } for _, child := range n.children { @@ -223,7 +225,7 @@ func (n *node) showWidgets() { if (w.isFake) { // don't display by default } else { - n.showWidgetPlacement(logInfo, "current:") + n.showWidgetPlacement(true, "current:") n.showView() } for _, child := range n.children { diff --git a/gocui/widget.go b/gocui/widget.go index 2690881..bfaa950 100644 --- a/gocui/widget.go +++ b/gocui/widget.go @@ -2,6 +2,8 @@ package main import ( "strconv" + + "go.wit.com/log" "go.wit.com/gui/widget" ) @@ -16,7 +18,7 @@ func initWidget(n *node) *guiWidget { w.cuiName = strconv.Itoa(n.WidgetId) if n.WidgetType == widget.Root { - log(logInfo, "setupWidget() FOUND ROOT w.id =", n.WidgetId) + log.Log(INFO, "setupWidget() FOUND ROOT w.id =", n.WidgetId) n.WidgetId = 0 me.rootNode = n return w diff --git a/nocui/args.go b/nocui/args.go index 07b3676..0dc994b 100644 --- a/nocui/args.go +++ b/nocui/args.go @@ -5,7 +5,7 @@ package main */ import ( - "go.wit.com/log" + log "go.wit.com/log" ) var NOW log.LogFlag diff --git a/nocui/go.mod b/nocui/go.mod new file mode 100644 index 0000000..0e2f341 --- /dev/null +++ b/nocui/go.mod @@ -0,0 +1,10 @@ +module go.wit.com/gui/toolkits/nocui + +go 1.21.4 + +require ( + go.wit.com/gui/widget v0.0.0-20240105185907-84aafa536a93 + go.wit.com/log v0.4.2 +) + +require go.wit.com/spew v0.0.0-20240101141411-c7b8e91573c9 // indirect diff --git a/nocui/go.sum b/nocui/go.sum new file mode 100644 index 0000000..1141ffb --- /dev/null +++ b/nocui/go.sum @@ -0,0 +1,6 @@ +go.wit.com/gui/widget v0.0.0-20240105185907-84aafa536a93 h1:zCzaHvXJJ/rWXmDc/v79VvM6W2lxxzJGfnW2lHCv3Ho= +go.wit.com/gui/widget v0.0.0-20240105185907-84aafa536a93/go.mod h1:A6/FaiFQtAHTjgo7c4FrokXe6bXX1Cowo35b2Lgi31E= +go.wit.com/log v0.4.2 h1:oYCOD7qCY0A+LsrQXPv5ETtVyD8AhIHgvNBMdly9hy0= +go.wit.com/log v0.4.2/go.mod h1:EZLvivLZpMoXl5AUBArH0zsIgr+c+WyNXm14BCF+sdw= +go.wit.com/spew v0.0.0-20240101141411-c7b8e91573c9 h1:UEX2EzLQPzLTfy/kUFQD7OXtvKn8wk/+jpDOkbl4ff4= +go.wit.com/spew v0.0.0-20240101141411-c7b8e91573c9/go.mod h1:qBpgJXThMMT15vym7/E4Ur9y8oOo2nP7t2RP52QHUNw= |
