move to 'go.wit.com/log'
Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
parent
4a079f8346
commit
2a9724d7a8
|
@ -11,7 +11,7 @@ var logWarn bool = true
|
||||||
var logInfo bool = false
|
var logInfo bool = false
|
||||||
var logVerbose bool = false
|
var logVerbose bool = false
|
||||||
|
|
||||||
func log(b bool, a ...any) {
|
func log(b *witlog.LogFlag, a ...any) {
|
||||||
witlog.Log(b, a...)
|
witlog.Log(b, a...)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -37,7 +37,8 @@ func action(a *widget.Action) {
|
||||||
log(logNow, "TODO: n.WidgetType =", n.WidgetType, "n.Name =", a.Name)
|
log(logNow, "TODO: n.WidgetType =", n.WidgetType, "n.Name =", a.Name)
|
||||||
} else {
|
} else {
|
||||||
if (a.A == nil) {
|
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 {
|
} else {
|
||||||
n.Set(a.A)
|
n.Set(a.A)
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,3 +3,14 @@ all: plugin
|
||||||
|
|
||||||
plugin:
|
plugin:
|
||||||
GO111MODULE="off" go build -v -x -buildmode=plugin -o ../nocui.so
|
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
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"go.wit.com/log"
|
||||||
"go.wit.com/gui/widget"
|
"go.wit.com/gui/widget"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -28,9 +29,9 @@ func (n *node) pad(at widget.ActionType) {
|
||||||
case widget.Grid:
|
case widget.Grid:
|
||||||
case widget.Box:
|
case widget.Box:
|
||||||
case widget.Textbox:
|
case widget.Textbox:
|
||||||
log(logError, "TODO: implement ActionType =", at)
|
log.Log(ERROR, "TODO: implement ActionType =", at)
|
||||||
default:
|
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:
|
case widget.Grid:
|
||||||
// t.uiGrid.SetPadded(true)
|
// t.uiGrid.SetPadded(true)
|
||||||
case widget.Box:
|
case widget.Box:
|
||||||
log(logInfo, "TODO: move() where =", p.ParentId)
|
log.Log(INFO, "TODO: move() where =", p.ParentId)
|
||||||
log(logInfo, "TODO: move() for widget =", n.WidgetId)
|
log.Log(INFO, "TODO: move() for widget =", n.WidgetId)
|
||||||
default:
|
default:
|
||||||
log(logError, "TODO: need to implement move() for type =", n.WidgetType)
|
log.Log(ERROR, "TODO: need to implement move() for type =", n.WidgetType)
|
||||||
log(logError, "TODO: need to implement move() for where =", p.ParentId)
|
log.Log(ERROR, "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 widget =", n.WidgetId)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (n *node) Delete() {
|
func (n *node) Delete() {
|
||||||
p := n.parent
|
p := n.parent
|
||||||
log(logNow, "uiDelete()", n.WidgetId, "to", p.WidgetId)
|
log.Log(NOW, "uiDelete()", n.WidgetId, "to", p.WidgetId)
|
||||||
|
|
||||||
switch p.WidgetType {
|
switch p.WidgetType {
|
||||||
case widget.Group:
|
case widget.Group:
|
||||||
|
@ -69,21 +70,21 @@ func (n *node) Delete() {
|
||||||
case widget.Grid:
|
case widget.Grid:
|
||||||
// t.uiGrid.SetPadded(true)
|
// t.uiGrid.SetPadded(true)
|
||||||
case widget.Box:
|
case widget.Box:
|
||||||
log(logNow, "tWidget.boxC =", p.Name)
|
log.Log(NOW, "tWidget.boxC =", p.Name)
|
||||||
log(logNow, "is there a tParent parent? =", p.parent)
|
log.Log(NOW, "is there a tParent parent? =", p.parent)
|
||||||
// this didn't work:
|
// this didn't work:
|
||||||
// tWidget.uiControl.Disable()
|
// tWidget.uiControl.Disable()
|
||||||
// sleep(.8)
|
// sleep(.8)
|
||||||
// tParent.uiBox.Append(tWidget.uiControl, stretchy)
|
// tParent.uiBox.Append(tWidget.uiControl, stretchy)
|
||||||
default:
|
default:
|
||||||
log(logError, "TODO: need to implement uiDelete() for widget =", n.WidgetId, n.WidgetType)
|
log.Log(ERROR, "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 parent =", p.WidgetId, p.WidgetType)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func doAction(a *widget.Action) {
|
func doAction(a *widget.Action) {
|
||||||
log(logNow, "doAction() START a.ActionType =", a.ActionType)
|
log.Log(INFO, "doAction() START a.ActionType =", a.ActionType)
|
||||||
log(logNow, "doAction() START a.S =", a.S)
|
log.Log(INFO, "doAction() START a.S =", a.S)
|
||||||
|
|
||||||
if (a.ActionType == widget.InitToolkit) {
|
if (a.ActionType == widget.InitToolkit) {
|
||||||
// TODO: make sure to only do this once
|
// TODO: make sure to only do this once
|
||||||
|
@ -95,11 +96,11 @@ func doAction(a *widget.Action) {
|
||||||
return
|
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 {
|
switch a.WidgetType {
|
||||||
case widget.Root:
|
case widget.Root:
|
||||||
me.rootNode = addNode(a)
|
me.rootNode = addNode(a)
|
||||||
log(logNow, "doAction() found rootNode")
|
log.Log(INFO, "doAction() found rootNode")
|
||||||
return
|
return
|
||||||
case widget.Flag:
|
case widget.Flag:
|
||||||
// flag(&a)
|
// flag(&a)
|
||||||
|
@ -143,11 +144,11 @@ func doAction(a *widget.Action) {
|
||||||
case widget.Delete:
|
case widget.Delete:
|
||||||
n.Delete()
|
n.Delete()
|
||||||
case widget.Move:
|
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)
|
newParent := me.rootNode.findWidgetId(a.ParentId)
|
||||||
n.move(newParent)
|
n.move(newParent)
|
||||||
default:
|
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)
|
||||||
}
|
}
|
||||||
|
|
|
@ -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")
|
||||||
|
}
|
|
@ -12,6 +12,7 @@ package main
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"go.wit.com/log"
|
||||||
"go.wit.com/gui/widget"
|
"go.wit.com/gui/widget"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -87,7 +88,7 @@ func (n *node) findWidgetId(id int) *node {
|
||||||
|
|
||||||
func (n *node) doUserEvent() {
|
func (n *node) doUserEvent() {
|
||||||
if (callback == nil) {
|
if (callback == nil) {
|
||||||
log(logError, "doUserEvent() callback == nil", n.WidgetId)
|
log.Log(ERROR, "doUserEvent() callback == nil", n.WidgetId)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
var a widget.Action
|
var a widget.Action
|
||||||
|
@ -98,9 +99,9 @@ func (n *node) doUserEvent() {
|
||||||
a.I = n.I
|
a.I = n.I
|
||||||
a.B = n.B
|
a.B = n.B
|
||||||
a.ActionType = widget.User
|
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
|
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
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -130,12 +131,12 @@ func addNode(a *widget.Action) *node {
|
||||||
// n.tk = new(guiWidget)
|
// n.tk = new(guiWidget)
|
||||||
|
|
||||||
if (a.WidgetType == widget.Root) {
|
if (a.WidgetType == widget.Root) {
|
||||||
log(logInfo, "addNode() Root")
|
log.Log(INFO, "addNode() Root")
|
||||||
return n
|
return n
|
||||||
}
|
}
|
||||||
|
|
||||||
if (me.rootNode.findWidgetId(a.WidgetId) != nil) {
|
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)
|
return me.rootNode.findWidgetId(a.WidgetId)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"go.wit.com/log"
|
||||||
"go.wit.com/gui/widget"
|
"go.wit.com/gui/widget"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -36,9 +37,9 @@ func (n *node) doWidgetClick() {
|
||||||
case widget.Box:
|
case widget.Box:
|
||||||
// n.showWidgetPlacement(logNow, "drawTree()")
|
// n.showWidgetPlacement(logNow, "drawTree()")
|
||||||
if (n.B) {
|
if (n.B) {
|
||||||
log(true, "BOX IS HORIZONTAL", n.Name)
|
log.Log(NOW, "BOX IS HORIZONTAL", n.Name)
|
||||||
} else {
|
} else {
|
||||||
log(true, "BOX IS VERTICAL", n.Name)
|
log.Log(NOW, "BOX IS VERTICAL", n.Name)
|
||||||
}
|
}
|
||||||
case widget.Button:
|
case widget.Button:
|
||||||
n.doUserEvent()
|
n.doUserEvent()
|
||||||
|
|
26
nocui/log.go
26
nocui/log.go
|
@ -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...)
|
|
||||||
}
|
|
|
@ -2,23 +2,24 @@ package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"sync"
|
"sync"
|
||||||
|
"go.wit.com/log"
|
||||||
"go.wit.com/gui/widget"
|
"go.wit.com/gui/widget"
|
||||||
)
|
)
|
||||||
|
|
||||||
var muAction sync.Mutex
|
var muAction sync.Mutex
|
||||||
|
|
||||||
func catchActionChannel() {
|
func catchActionChannel() {
|
||||||
log(logNow, "catchActionChannel() START")
|
log.Log(NOW, "catchActionChannel() START")
|
||||||
for {
|
for {
|
||||||
log(logNow, "catchActionChannel() for loop")
|
log.Log(NOW, "catchActionChannel() for loop")
|
||||||
select {
|
select {
|
||||||
case a := <-pluginChan:
|
case a := <-pluginChan:
|
||||||
log(logNow, "catchActionChannel() SELECT widget id =", a.WidgetId, a.Name)
|
log.Log(NOW, "catchActionChannel() SELECT widget id =", a.WidgetId, a.Name)
|
||||||
log(logNow, "catchActionChannel() STUFF", a.WidgetId, a.ActionType, a.WidgetType)
|
log.Log(NOW, "catchActionChannel() STUFF", a.WidgetId, a.ActionType, a.WidgetType)
|
||||||
muAction.Lock()
|
muAction.Lock()
|
||||||
doAction(&a)
|
doAction(&a)
|
||||||
muAction.Unlock()
|
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
|
// This is important. This sets the defaults for the gui. Without this, there isn't correct padding, etc
|
||||||
func init() {
|
func init() {
|
||||||
log(logNow, "Init() START")
|
log.Log(INFO, "Init()")
|
||||||
log(logInfo, "Init()")
|
|
||||||
|
|
||||||
// andlabs = make(map[int]*andlabsT)
|
// andlabs = make(map[int]*andlabsT)
|
||||||
pluginChan = make(chan widget.Action, 1)
|
pluginChan = make(chan widget.Action, 1)
|
||||||
|
|
||||||
log(logNow, "Init() start channel reciever")
|
log.Log(NOW, "Init() start channel reciever")
|
||||||
go catchActionChannel()
|
go catchActionChannel()
|
||||||
go simpleStdin()
|
go simpleStdin()
|
||||||
log(logNow, "Init() END")
|
log.Log(NOW, "Init() END")
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,6 +7,7 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
|
"go.wit.com/log"
|
||||||
"go.wit.com/gui/widget"
|
"go.wit.com/gui/widget"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -17,10 +18,10 @@ func simpleStdin() {
|
||||||
s = strings.TrimSuffix(s, "\n")
|
s = strings.TrimSuffix(s, "\n")
|
||||||
switch s {
|
switch s {
|
||||||
case "l":
|
case "l":
|
||||||
log(true, "list widgets")
|
log.Log(NOW, "list widgets")
|
||||||
me.rootNode.listWidgets()
|
me.rootNode.listWidgets()
|
||||||
case "b":
|
case "b":
|
||||||
log(true, "show buttons")
|
log.Log(NOW, "show buttons")
|
||||||
me.rootNode.showButtons()
|
me.rootNode.showButtons()
|
||||||
case "d":
|
case "d":
|
||||||
var a widget.Action
|
var a widget.Action
|
||||||
|
@ -34,7 +35,7 @@ func simpleStdin() {
|
||||||
fmt.Println("'d': enable debugging")
|
fmt.Println("'d': enable debugging")
|
||||||
default:
|
default:
|
||||||
i, _ := strconv.Atoi(s)
|
i, _ := strconv.Atoi(s)
|
||||||
log(true, "got input:", i)
|
log.Log(NOW, "got input:", i)
|
||||||
n := me.rootNode.findWidgetId(i)
|
n := me.rootNode.findWidgetId(i)
|
||||||
if (n != nil) {
|
if (n != nil) {
|
||||||
n.dumpWidget("found node")
|
n.dumpWidget("found node")
|
||||||
|
@ -55,7 +56,7 @@ func (n *node) showButtons() {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (n *node) dumpWidget(pad string) {
|
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
|
var depth int = 0
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"go.wit.com/log"
|
||||||
"go.wit.com/gui/widget"
|
"go.wit.com/gui/widget"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -11,7 +12,7 @@ func initWidget(n *node) *guiWidget {
|
||||||
// Set(w, "default")
|
// Set(w, "default")
|
||||||
|
|
||||||
if n.WidgetType == widget.Root {
|
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
|
n.WidgetId = 0
|
||||||
me.rootNode = n
|
me.rootNode = n
|
||||||
return w
|
return w
|
||||||
|
|
Loading…
Reference in New Issue