move to 'go.wit.com/log'

Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
Jeff Carr 2024-01-08 20:17:49 -06:00
parent 4a079f8346
commit 2a9724d7a8
11 changed files with 89 additions and 68 deletions

View File

@ -11,7 +11,7 @@ var logWarn bool = true
var logInfo bool = false
var logVerbose bool = false
func log(b bool, a ...any) {
func log(b *witlog.LogFlag, a ...any) {
witlog.Log(b, a...)
}

View File

@ -37,7 +37,8 @@ func action(a *widget.Action) {
log(logNow, "TODO: n.WidgetType =", n.WidgetType, "n.Name =", a.Name)
} else {
if (a.A == nil) {
log(logError, "TODO: Set here. a == nil", a.ActionType, "WidgetType =", a.WidgetType, "Name =", a.Name)
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)
} else {
n.Set(a.A)
}

View File

@ -3,3 +3,14 @@ all: plugin
plugin:
GO111MODULE="off" go build -v -x -buildmode=plugin -o ../nocui.so
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

View File

@ -1,6 +1,7 @@
package main
import (
"go.wit.com/log"
"go.wit.com/gui/widget"
)
@ -28,9 +29,9 @@ func (n *node) pad(at widget.ActionType) {
case widget.Grid:
case widget.Box:
case widget.Textbox:
log(logError, "TODO: implement ActionType =", at)
log.Log(ERROR, "TODO: implement ActionType =", at)
default:
log(logError, "TODO: implement pad() for", at)
log.Log(ERROR, "TODO: implement pad() for", at)
}
}
@ -46,18 +47,18 @@ func (n *node) move(newParent *node) {
case widget.Grid:
// t.uiGrid.SetPadded(true)
case widget.Box:
log(logInfo, "TODO: move() where =", p.ParentId)
log(logInfo, "TODO: move() for widget =", n.WidgetId)
log.Log(INFO, "TODO: move() where =", p.ParentId)
log.Log(INFO, "TODO: move() for widget =", n.WidgetId)
default:
log(logError, "TODO: need to implement move() for type =", n.WidgetType)
log(logError, "TODO: need to implement move() for where =", p.ParentId)
log(logError, "TODO: need to implement move() for widget =", n.WidgetId)
log.Log(ERROR, "TODO: need to implement move() for type =", n.WidgetType)
log.Log(ERROR, "TODO: need to implement move() for where =", p.ParentId)
log.Log(ERROR, "TODO: need to implement move() for widget =", n.WidgetId)
}
}
func (n *node) Delete() {
p := n.parent
log(logNow, "uiDelete()", n.WidgetId, "to", p.WidgetId)
log.Log(NOW, "uiDelete()", n.WidgetId, "to", p.WidgetId)
switch p.WidgetType {
case widget.Group:
@ -69,21 +70,21 @@ func (n *node) Delete() {
case widget.Grid:
// t.uiGrid.SetPadded(true)
case widget.Box:
log(logNow, "tWidget.boxC =", p.Name)
log(logNow, "is there a tParent parent? =", p.parent)
log.Log(NOW, "tWidget.boxC =", p.Name)
log.Log(NOW, "is there a tParent parent? =", p.parent)
// this didn't work:
// tWidget.uiControl.Disable()
// sleep(.8)
// tParent.uiBox.Append(tWidget.uiControl, stretchy)
default:
log(logError, "TODO: need to implement uiDelete() for widget =", n.WidgetId, n.WidgetType)
log(logError, "TODO: need to implement uiDelete() for parent =", p.WidgetId, p.WidgetType)
log.Log(ERROR, "TODO: need to implement uiDelete() for widget =", n.WidgetId, n.WidgetType)
log.Log(ERROR, "TODO: need to implement uiDelete() for parent =", p.WidgetId, p.WidgetType)
}
}
func doAction(a *widget.Action) {
log(logNow, "doAction() START a.ActionType =", a.ActionType)
log(logNow, "doAction() START a.S =", a.S)
log.Log(INFO, "doAction() START a.ActionType =", a.ActionType)
log.Log(INFO, "doAction() START a.S =", a.S)
if (a.ActionType == widget.InitToolkit) {
// TODO: make sure to only do this once
@ -95,11 +96,11 @@ func doAction(a *widget.Action) {
return
}
log(logNow, "doAction() START a.WidgetId =", a.WidgetId, "a.ParentId =", a.ParentId)
log.Log(INFO, "doAction() START a.WidgetId =", a.WidgetId, "a.ParentId =", a.ParentId)
switch a.WidgetType {
case widget.Root:
me.rootNode = addNode(a)
log(logNow, "doAction() found rootNode")
log.Log(INFO, "doAction() found rootNode")
return
case widget.Flag:
// flag(&a)
@ -143,11 +144,11 @@ func doAction(a *widget.Action) {
case widget.Delete:
n.Delete()
case widget.Move:
log(logNow, "doAction() attempt to move() =", a.ActionType, a.WidgetType)
log.Log(INFO, "doAction() attempt to move() =", a.ActionType, a.WidgetType)
newParent := me.rootNode.findWidgetId(a.ParentId)
n.move(newParent)
default:
log(logError, "doAction() Unknown =", a.ActionType, a.WidgetType)
log.Log(ERROR, "doAction() Unknown =", a.ActionType, a.WidgetType)
}
log(logInfo, "doAction() END =", a.ActionType, a.WidgetType)
log.Log(INFO, "doAction() END =", a.ActionType, a.WidgetType)
}

30
nocui/args.go Normal file
View File

@ -0,0 +1,30 @@
package main
/*
this enables command line options from other packages like 'gui' and 'log'
*/
import (
"go.wit.com/log"
)
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")
}

View File

@ -12,6 +12,7 @@ package main
*/
import (
"go.wit.com/log"
"go.wit.com/gui/widget"
)
@ -87,7 +88,7 @@ func (n *node) findWidgetId(id int) *node {
func (n *node) doUserEvent() {
if (callback == nil) {
log(logError, "doUserEvent() callback == nil", n.WidgetId)
log.Log(ERROR, "doUserEvent() callback == nil", n.WidgetId)
return
}
var a widget.Action
@ -98,9 +99,9 @@ func (n *node) doUserEvent() {
a.I = n.I
a.B = n.B
a.ActionType = widget.User
log(logInfo, "doUserEvent() START: send a user event to the callback channel")
log.Log(INFO, "doUserEvent() START: send a user event to the callback channel")
callback <- a
log(logInfo, "doUserEvent() END: sent a user event to the callback channel")
log.Log(INFO, "doUserEvent() END: sent a user event to the callback channel")
return
}
@ -130,12 +131,12 @@ func addNode(a *widget.Action) *node {
// n.tk = new(guiWidget)
if (a.WidgetType == widget.Root) {
log(logInfo, "addNode() Root")
log.Log(INFO, "addNode() Root")
return n
}
if (me.rootNode.findWidgetId(a.WidgetId) != nil) {
log(logError, "addNode() WidgetId already exists", a.WidgetId)
log.Log(ERROR, "addNode() WidgetId already exists", a.WidgetId)
return me.rootNode.findWidgetId(a.WidgetId)
}

View File

@ -1,6 +1,7 @@
package main
import (
"go.wit.com/log"
"go.wit.com/gui/widget"
)
@ -36,9 +37,9 @@ func (n *node) doWidgetClick() {
case widget.Box:
// n.showWidgetPlacement(logNow, "drawTree()")
if (n.B) {
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)
}
case widget.Button:
n.doUserEvent()

View File

@ -1,26 +0,0 @@
package main
import (
witlog "go.wit.com/log"
)
// various debugging flags
var logNow bool = true // useful for active development
var logError bool = true
var logWarn bool = false
var logInfo bool = false
var logVerbose bool = false
var outputS []string
func log(b bool, a ...any) {
witlog.Log(b, a...)
}
func sleep(a ...any) {
witlog.Sleep(a...)
}
func exit(a ...any) {
witlog.Exit(a...)
}

View File

@ -2,23 +2,24 @@ package main
import (
"sync"
"go.wit.com/log"
"go.wit.com/gui/widget"
)
var muAction sync.Mutex
func catchActionChannel() {
log(logNow, "catchActionChannel() START")
log.Log(NOW, "catchActionChannel() START")
for {
log(logNow, "catchActionChannel() for loop")
log.Log(NOW, "catchActionChannel() for loop")
select {
case a := <-pluginChan:
log(logNow, "catchActionChannel() SELECT widget id =", a.WidgetId, a.Name)
log(logNow, "catchActionChannel() STUFF", a.WidgetId, a.ActionType, a.WidgetType)
log.Log(NOW, "catchActionChannel() SELECT widget id =", a.WidgetId, a.Name)
log.Log(NOW, "catchActionChannel() STUFF", a.WidgetId, a.ActionType, a.WidgetType)
muAction.Lock()
doAction(&a)
muAction.Unlock()
log(logNow, "catchActionChannel() STUFF END", a.WidgetId, a.ActionType, a.WidgetType)
log.Log(NOW, "catchActionChannel() STUFF END", a.WidgetId, a.ActionType, a.WidgetType)
}
}
}
@ -42,14 +43,13 @@ func PluginChannel() chan widget.Action {
// This is important. This sets the defaults for the gui. Without this, there isn't correct padding, etc
func init() {
log(logNow, "Init() START")
log(logInfo, "Init()")
log.Log(INFO, "Init()")
// andlabs = make(map[int]*andlabsT)
pluginChan = make(chan widget.Action, 1)
log(logNow, "Init() start channel reciever")
log.Log(NOW, "Init() start channel reciever")
go catchActionChannel()
go simpleStdin()
log(logNow, "Init() END")
log.Log(NOW, "Init() END")
}

View File

@ -7,6 +7,7 @@ import (
"strings"
"strconv"
"go.wit.com/log"
"go.wit.com/gui/widget"
)
@ -17,10 +18,10 @@ func simpleStdin() {
s = strings.TrimSuffix(s, "\n")
switch s {
case "l":
log(true, "list widgets")
log.Log(NOW, "list widgets")
me.rootNode.listWidgets()
case "b":
log(true, "show buttons")
log.Log(NOW, "show buttons")
me.rootNode.showButtons()
case "d":
var a widget.Action
@ -34,7 +35,7 @@ func simpleStdin() {
fmt.Println("'d': enable debugging")
default:
i, _ := strconv.Atoi(s)
log(true, "got input:", i)
log.Log(NOW, "got input:", i)
n := me.rootNode.findWidgetId(i)
if (n != nil) {
n.dumpWidget("found node")
@ -55,7 +56,7 @@ func (n *node) showButtons() {
}
func (n *node) dumpWidget(pad string) {
log(true, "node:", pad, n.WidgetId, ",", n.WidgetType, ",", n.Name)
log.Log(NOW, "node:", pad, n.WidgetId, ",", n.WidgetType, ",", n.Name)
}
var depth int = 0

View File

@ -1,6 +1,7 @@
package main
import (
"go.wit.com/log"
"go.wit.com/gui/widget"
)
@ -11,7 +12,7 @@ func initWidget(n *node) *guiWidget {
// Set(w, "default")
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