var value any

Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
Jeff Carr 2024-01-11 19:10:24 -06:00
parent c4582b0b30
commit 3b258d0ce0
20 changed files with 94 additions and 111 deletions

View File

@ -28,10 +28,10 @@ func (n *node) setFake() {
// set the widget start width & height
func (n *node) addWidget() {
nw := n.tk
log.Log(INFO, "setStartWH() w.id =", n.WidgetId, "n.name", n.Name)
log.Log(INFO, "setStartWH() w.id =", n.WidgetId, "n.name", n.progname)
switch n.WidgetType {
case widget.Root:
log.Log(INFO, "setStartWH() rootNode w.id =", n.WidgetId, "w.name", n.Name)
log.Log(INFO, "setStartWH() rootNode w.id =", n.WidgetId, "w.name", n.progname)
nw.color = &colorRoot
n.setFake()
return

View File

@ -5,19 +5,19 @@ import (
"go.wit.com/gui/widget"
)
func (n *node) setCheckbox(b bool) {
func (n *node) setCheckbox(b any) {
w := n.tk
if (n.WidgetType != widget.Checkbox) {
return
}
if (b) {
n.B = b
n.Text = "X " + n.Name
if widget.GetBool(b) {
n.value = b
n.tk.label = "X " + n.label
} else {
n.B = b
n.Text = " " + n.Name
n.value = b
n.tk.label = " " + n.label
}
t := len(n.Text) + 1
t := len(n.tk.label) + 1
w.gocuiSize.w1 = w.gocuiSize.w0 + t
// w.realWidth = w.gocuiSize.Width() + me.PadW

View File

@ -26,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.Log(NOW, "updateCurrent()", n.Name)
log.Log(NOW, "updateCurrent()", n.progname)
if n.WidgetType == widget.Tab {
if n.IsCurrent() {
// n.tk.color = &colorActiveT
@ -84,17 +84,17 @@ func setCurrentTab(n *node) {
w.isCurrent = true
p := n.parent.tk
p.isCurrent = true
log.Log(NOW, "setCurrent()", n.Name)
log.Log(NOW, "setCurrent()", n.progname)
}
func (n *node) doWidgetClick() {
switch n.WidgetType {
case widget.Root:
// THIS IS THE BEGINING OF THE LAYOUT
log.Log(NOW, "doWidgetClick()", n.Name)
log.Log(NOW, "doWidgetClick()", n.progname)
redoWindows(0,0)
case widget.Flag:
log.Log(NOW, "doWidgetClick() FLAG widget name =", n.Name)
log.Log(NOW, "doWidgetClick() FLAG widget name =", n.progname)
log.Log(NOW, "doWidgetClick() if this is the dropdown menu, handle it here?")
case widget.Window:
if (me.currentWindow == n) {
@ -112,7 +112,7 @@ func (n *node) doWidgetClick() {
n.redoTabs(me.TabW, me.TabH)
for _, child := range n.children {
if (child.currentTab == true) {
log.Log(NOW, "FOUND CURRENT TAB", child.Name)
log.Log(NOW, "FOUND CURRENT TAB", child.progname)
setCurrentTab(child)
child.placeWidgets(me.RawW, me.RawH)
child.showWidgets()
@ -149,7 +149,7 @@ func (n *node) doWidgetClick() {
// n.placeWidgets(p.tk.startH, newH)
n.toggleTree()
case widget.Checkbox:
if (n.B) {
if (widget.GetBool(n.value)) {
n.setCheckbox(false)
} else {
n.setCheckbox(true)
@ -166,10 +166,10 @@ func (n *node) doWidgetClick() {
n.showWidgets()
case widget.Box:
// w.showWidgetPlacement(logNow, "drawTree()")
if (n.horizontal) {
log.Log(NOW, "BOX IS HORIZONTAL", n.Name)
if (n.direction == widget.Horizontal) {
log.Log(NOW, "BOX IS HORIZONTAL", n.progname)
} else {
log.Log(NOW, "BOX IS VERTICAL", n.Name)
log.Log(NOW, "BOX IS VERTICAL", n.progname)
}
// n.placeWidgets()
n.toggleTree()
@ -207,17 +207,17 @@ func (n *node) doWidgetClick() {
} else {
var dnsList string
for i, s := range n.vals {
log.Log(NOW, "AddText()", n.Name, i, s)
log.Log(NOW, "AddText()", n.progname, i, s)
dnsList += s + "\n"
}
me.ddNode = n
log.Log(NOW, "new dns list should be set to:", dnsList)
me.ddview.Text = dnsList
me.ddview.label = dnsList
me.ddview.SetText(dnsList)
me.ddview.SetVisible(true)
}
for i, s := range n.vals {
log.Log(NOW, "AddText()", n.Name, i, s)
log.Log(NOW, "AddText()", n.progname, i, s)
}
default:
}
@ -262,8 +262,8 @@ func click(g *gocui.Gui, v *gocui.View) error {
// n := me.rootNode.findWidgetName(v.Name())
n := findUnderMouse()
if (n != nil) {
log.Log(NOW, "click() Found widget =", n.WidgetId, n.Name, ",", n.Text)
if (n.Name == "DropBox") {
log.Log(NOW, "click() Found widget =", n.WidgetId, n.progname, ",", n.label)
if (n.progname == "DropBox") {
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
@ -333,7 +333,7 @@ func ctrlDown(g *gocui.Gui, v *gocui.View) error {
found = findUnderMouse()
if (me.ctrlDown == nil) {
setupCtrlDownWidget()
me.ctrlDown.Text = found.Name
me.ctrlDown.label = found.progname
me.ctrlDown.tk.cuiName = "ctrlDown"
// me.ctrlDown.parent = me.rootNode
}
@ -341,7 +341,7 @@ func ctrlDown(g *gocui.Gui, v *gocui.View) error {
if (found == nil) {
found = me.rootNode
}
me.ctrlDown.Text = found.Name
me.ctrlDown.label = found.progname
newR := found.realGocuiSize()
cd.gocuiSize.w0 = newR.w0
cd.gocuiSize.h0 = newR.h0

View File

@ -46,12 +46,12 @@ func (n *node) showWidgetPlacement(b bool, s string) {
s1 += fmt.Sprintf("At(%2d,%2d) ", n.AtW, n.AtH)
}
}
tmp := "." + n.Name + "."
tmp := "." + n.progname + "."
log.Log(INFO, s1, s, n.WidgetType, ",", tmp) // , "text=", w.text)
}
func (n *node) dumpWidget(pad string) {
log.Log(NOW, "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.progname =", n.progname, ", n.label =", n.label)
}
func (n *node) listWidgets() {

View File

@ -144,7 +144,7 @@ func addDebugKeys(g *gocui.Gui) {
func(g *gocui.Gui, v *gocui.View) error {
if (showDebug) {
var a widget.Action
a.B = true
a.Value = true
a.ActionType = widget.EnableDebug
callback <- a
}

View File

@ -45,7 +45,7 @@ func catchActionChannel() {
log.Log(ERROR, "ERROR: console did not initialize")
continue
}
log.Log(INFO, "catchActionChannel()", a.WidgetId, a.ActionType, a.WidgetType, a.Name)
log.Log(INFO, "catchActionChannel()", a.WidgetId, a.ActionType, a.WidgetType, a.ProgName)
action(&a)
}
}

View File

@ -86,7 +86,7 @@ func mouseUp(g *gocui.Gui, v *gocui.View) error {
if (newZone != "") {
if (me.ddNode != nil) {
me.ddNode.SetText(newZone)
me.ddNode.S = newZone
me.ddNode.value = newZone
me.ddNode.doUserEvent()
}
}

View File

@ -21,12 +21,12 @@ func (n *node) placeBox(startW int, startH int) {
newR := child.realGocuiSize()
w := newR.w1 - newR.w0
h := newR.h1 - newR.h0
if (n.horizontal) {
log.Log(NOW, "BOX IS HORIZONTAL", n.Name, "newWH()", newW, newH, "child()", w, h, child.Name)
if (n.direction == widget.Horizontal) {
log.Log(NOW, "BOX IS HORIZONTAL", n.progname, "newWH()", newW, newH, "child()", w, h, child.progname)
// expand based on the child width
newW += w
} else {
log.Log(NOW, "BOX IS VERTICAL ", n.Name, "newWH()", newW, newH, "child()", w, h, child.Name)
log.Log(NOW, "BOX IS VERTICAL ", n.progname, "newWH()", newW, newH, "child()", w, h, child.progname)
// expand based on the child height
newH += h
}
@ -105,7 +105,7 @@ func (n *node) placeGrid(startW int, startH int) {
w.heights[child.AtH] = childH
}
// child.showWidgetPlacement(logInfo, "grid: ")
log.Log(INFO, "placeGrid:", child.Name, "child()", childW, childH, "At()", child.AtW, child.AtH)
log.Log(INFO, "placeGrid:", child.progname, "child()", childW, childH, "At()", child.AtW, child.AtH)
}
// find the width and height offset of the grid for AtW,AtH
@ -128,7 +128,7 @@ func (n *node) placeGrid(startW int, startH int) {
newW := startW + totalW
newH := startH + totalH
log.Log(INFO, "placeGrid:", child.Name, "new()", newW, newH, "At()", child.AtW, child.AtH)
log.Log(INFO, "placeGrid:", child.progname, "new()", newW, newH, "At()", child.AtW, child.AtH)
child.placeWidgets(newW, newH)
child.showWidgetPlacement(true, "grid2:")
}
@ -178,7 +178,7 @@ func (n *node) realGocuiSize() *rectType {
func (n *node) textSize() (int, int) {
var width, height int
for _, s := range strings.Split(n.Text, "\n") {
for _, s := range strings.Split(widget.GetString(n.value), "\n") {
if (width < len(s)) {
width = len(s)
}

View File

@ -8,7 +8,7 @@ import (
)
func action(a *widget.Action) {
log.Log(INFO, "action() START", a.WidgetId, a.ActionType, a.WidgetType, a.Name)
log.Log(INFO, "action() START", a.WidgetId, a.ActionType, a.WidgetType, a.ProgName)
n := me.rootNode.findWidgetId(a.WidgetId)
var w *guiWidget
if (n != nil) {
@ -24,32 +24,32 @@ func action(a *widget.Action) {
// this is done to protect the plugin being 'refreshed' with the
// widget binary tree. TODO: find a way to keep them in sync
log.Log(ERROR, "action() Add ignored for already defined widget",
a.WidgetId, a.ActionType, a.WidgetType, a.Name)
a.WidgetId, a.ActionType, a.WidgetType, a.ProgName)
}
case widget.Show:
if (a.B) {
if widget.GetBool(a.Value) {
n.showView()
} else {
n.hideWidgets()
}
case widget.Set:
if a.WidgetType == widget.Flag {
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)
log.Log(NOW, "TODO: set flag here", a.ActionType, a.WidgetType, a.ProgName)
log.Log(NOW, "TODO: n.WidgetType =", n.WidgetType, "n.progname =", a.ProgName)
} else {
if (a.A == nil) {
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)
if (a.Value == nil) {
log.Log(ERROR, "TODO: Set here. a == nil id =", a.WidgetId, "type =", a.WidgetType, "Name =", a.ProgName)
log.Log(ERROR, "TODO: Set here. id =", a.WidgetId, "n.progname =", n.progname)
} else {
n.Set(a.A)
n.Set(a.Value)
}
}
case widget.SetText:
n.SetText(a.S)
n.SetText(widget.GetString(a.Value))
case widget.AddText:
n.AddText(a.S)
n.AddText(widget.GetString(a.Value))
case widget.Move:
log.Log(NOW, "attempt to move() =", a.ActionType, a.WidgetType, a.Name)
log.Log(NOW, "attempt to move() =", a.ActionType, a.WidgetType, a.ProgName)
case widget.CloseToolkit:
log.Log(NOW, "attempting to close the plugin and release stdout and stderr")
standardExit()
@ -57,18 +57,18 @@ func action(a *widget.Action) {
if n.Visible() {
// widget was already shown
} else {
log.Log(INFO, "Setting Visable to true", a.Name)
log.Log(INFO, "Setting Visable to true", a.ProgName)
n.SetVisible(true)
}
case widget.Disable:
if n.Visible() {
log.Log(INFO, "Setting Visable to false", a.Name)
log.Log(INFO, "Setting Visable to false", a.ProgName)
n.SetVisible(false)
} else {
// widget was already hidden
}
default:
log.Log(ERROR, "action() ActionType =", a.ActionType, "WidgetType =", a.WidgetType, "Name =", a.Name)
log.Log(ERROR, "action() ActionType =", a.ActionType, "WidgetType =", a.WidgetType, "Name =", a.ProgName)
}
log.Log(INFO, "action() END")
}
@ -80,7 +80,7 @@ func (n *node) AddText(text string) {
}
n.vals = append(n.vals, text)
for i, s := range n.vals {
log.Log(NOW, "AddText()", n.Name, i, s)
log.Log(NOW, "AddText()", n.progname, i, s)
}
n.SetText(text)
}
@ -91,12 +91,8 @@ func (n *node) SetText(text string) {
log.Log(NOW, "widget is nil")
return
}
if (n.Text != text) {
n.Text = text
changed = true
}
if (n.S != text) {
n.S = text
if widget.GetString(n.value) != text {
n.value = text
changed = true
}
if (! changed) {
@ -114,15 +110,8 @@ func (n *node) Set(val any) {
// w := n.tk
log.Log(INFO, "Set() value =", val)
switch v := val.(type) {
case bool:
n.B = val.(bool)
n.setCheckbox(val.(bool))
case string:
n.SetText(val.(string))
case int:
n.I = val.(int)
default:
log.Log(ERROR, "Set() unknown type =", val, v)
n.value = val
if (n.WidgetType != widget.Checkbox) {
n.setCheckbox(val)
}
}

View File

@ -50,8 +50,7 @@ func makeOutputWidget(g *gocui.Gui, stringFromMouseClick string) *gocui.View {
if (me.logStdout == nil) {
a := new(widget.Action)
a.Name = "stdout"
a.Text = "stdout"
a.ProgName = "stdout"
a.WidgetType = widget.Stdout
a.WidgetId = -3
a.ParentId = 0

View File

@ -118,6 +118,9 @@ type guiWidget struct {
v *gocui.View // this is nil if the widget is not displayed
cuiName string // what gocui uses to reference the widget
// the actual text to display in the console
label string
// the logical size of the widget
// For example, 40x12 would be the center of a normal terminal
// size rectType

View File

@ -24,8 +24,8 @@ func (w *guiWidget) Height() int {
}
func (n *node) gocuiSetWH(sizeW, sizeH int) {
w := len(n.Text)
lines := strings.Split(n.Text, "\n")
w := len(widget.GetString(n.value))
lines := strings.Split(widget.GetString(n.value), "\n")
h := len(lines)
tk := n.tk
@ -78,7 +78,7 @@ func redoWindows(nextW int, nextH int) {
sizeW := w.Width() + me.WindowPadW
sizeH := w.Height()
nextW += sizeW
log.Log(NOW, "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.progname)
if n.hasTabs {
n.redoTabs(me.TabW, me.TabH)
@ -105,7 +105,7 @@ func (p *node) redoTabs(nextW int, nextH int) {
sizeW := w.Width() + me.TabPadW
sizeH := w.Height()
log.Log(NOW, "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.progname)
nextW += sizeW
}
}

View File

@ -27,7 +27,7 @@ func (n *node) textResize() bool {
var width, height int = 0, 0
var changed bool = false
for i, s := range splitLines(n.Text) {
for i, s := range splitLines(n.tk.label) {
log.Log(INFO, "textResize() len =", len(s), i, s)
if (width < len(s)) {
width = len(s)
@ -68,7 +68,7 @@ func (n *node) showView() {
n.recreateView()
}
x0, y0, x1, y1, err := me.baseGui.ViewPosition(w.cuiName)
log.Log(INFO, "showView() w.v already defined for widget", n.Name, err)
log.Log(INFO, "showView() w.v already defined for widget", n.progname, err)
// n.smartGocuiSize()
changed := n.textResize()
@ -78,7 +78,7 @@ func (n *node) showView() {
} else {
log.Log(NOW, "showView() Clear() and Fprint() here wId =", w.cuiName)
w.v.Clear()
fmt.Fprint(w.v, n.Text)
fmt.Fprint(w.v, n.tk.label)
n.SetVisible(false)
n.SetVisible(true)
return
@ -114,7 +114,7 @@ func (n *node) showView() {
func (n *node) recreateView() {
var err error
w := n.tk
log.Log(ERROR, "recreateView() START", n.WidgetType, n.Name)
log.Log(ERROR, "recreateView() START", n.WidgetType, n.progname)
if (me.baseGui == nil) {
log.Log(ERROR, "recreateView() ERROR: me.baseGui == nil", w)
return
@ -124,11 +124,11 @@ func (n *node) recreateView() {
me.baseGui.DeleteView(w.cuiName)
w.v = nil
if (n.Name == "CLOUDFLARE_EMAIL") {
n.showWidgetPlacement(true, "n.Name=" + n.Name + " n.Text=" + n.Text + " " + w.cuiName)
if (n.progname == "CLOUDFLARE_EMAIL") {
n.showWidgetPlacement(true, "n.progname=" + n.progname + " n.tk.label=" + n.tk.label + " " + w.cuiName)
n.dumpWidget("jwc")
n.textResize()
n.showWidgetPlacement(true, "n.Name=" + n.Name + " n.Text=" + n.Text + " " + w.cuiName)
n.showWidgetPlacement(true, "n.progname=" + n.progname + " n.tk.label=" + n.tk.label + " " + w.cuiName)
}
a := w.gocuiSize.w0
@ -162,8 +162,8 @@ func (n *node) recreateView() {
w.v.Wrap = true
w.v.Frame = w.frame
w.v.Clear()
fmt.Fprint(w.v, n.Text)
// n.showWidgetPlacement(true, "n.Name=" + n.Name + " n.Text=" + n.Text + " " + w.cuiName)
fmt.Fprint(w.v, n.tk.label)
// n.showWidgetPlacement(true, "n.progname=" + n.progname + " n.tk.label=" + n.tk.label + " " + w.cuiName)
// n.dumpWidget("jwc 2")
// if you don't do this here, it will be black & white only
@ -174,8 +174,8 @@ func (n *node) recreateView() {
w.v.SelFgColor = w.color.selFg
w.v.SelBgColor = w.color.selBg
}
if (n.Name == "CLOUDFLARE_EMAIL") {
n.showWidgetPlacement(true, "n.Name=" + n.Name + " n.Text=" + n.Text + " " + w.cuiName)
if (n.progname == "CLOUDFLARE_EMAIL") {
n.showWidgetPlacement(true, "n.progname=" + n.progname + " n.tk.label=" + n.tk.label + " " + w.cuiName)
n.dumpTree(true)
}
log.Log(ERROR, "recreateView() END")

View File

@ -24,14 +24,6 @@ func initWidget(n *node) *guiWidget {
return w
}
if (n.WidgetType == widget.Box) {
if (n.B) {
n.horizontal = true
} else {
n.horizontal = false
}
}
if (n.WidgetType == widget.Grid) {
w.widths = make(map[int]int) // how tall each row in the grid is
w.heights = make(map[int]int) // how wide each column in the grid is
@ -42,7 +34,7 @@ func initWidget(n *node) *guiWidget {
func setupCtrlDownWidget() {
a := new(widget.Action)
a.Name = "ctrlDown"
a.ProgName = "ctrlDown"
a.WidgetType = widget.Dialog
a.WidgetId = -1
a.ParentId = 0
@ -128,8 +120,8 @@ func addDropdown() *node {
n.ParentId = 0
// copy the data from the action message
n.Name = "DropBox"
n.Text = "DropBox text"
n.progname = "DropBox"
n.tk.label = "DropBox text"
// store the internal toolkit information
n.tk = new(guiWidget)

View File

@ -70,7 +70,7 @@ func (n *node) Delete() {
case widget.Grid:
// t.uiGrid.SetPadded(true)
case widget.Box:
log.Log(NOW, "tWidget.boxC =", p.Name)
log.Log(NOW, "tWidget.boxC =", p.progname)
log.Log(NOW, "is there a tParent parent? =", p.parent)
// this didn't work:
// tWidget.uiControl.Disable()
@ -84,7 +84,7 @@ func (n *node) Delete() {
func doAction(a *widget.Action) {
log.Log(INFO, "doAction() START a.ActionType =", a.ActionType)
log.Log(INFO, "doAction() START a.S =", a.S)
log.Log(INFO, "doAction() START a.ProgName =", a.ProgName)
if (a.ActionType == widget.InitToolkit) {
// TODO: make sure to only do this once
@ -125,7 +125,7 @@ func doAction(a *widget.Action) {
case widget.GetText:
switch a.WidgetType {
case widget.Textbox:
a.S = n.S
a.Value = n.value
}
case widget.Set:
// n.setText(a.S)

View File

@ -34,10 +34,10 @@ type node struct {
WidgetType widget.WidgetType
ParentId int // parent ID
// Name string
// Text string
// a reference name for programming and debuggign. Must be unique
progname string
// the text used for button labesl, window titles, checkbox names, etc
label string
// horizontal means layout widgets like books on a bookshelf

View File

@ -24,7 +24,7 @@ func (n *node) doWidgetClick() {
// n.placeWidgets()
// n.toggleTree()
case widget.Checkbox:
if (n.B) {
if widget.GetBool(n.value) {
// n.setCheckbox(false)
} else {
// n.setCheckbox(true)
@ -36,10 +36,10 @@ func (n *node) doWidgetClick() {
// n.showWidgets()
case widget.Box:
// n.showWidgetPlacement(logNow, "drawTree()")
if (n.B) {
log.Log(NOW, "BOX IS HORIZONTAL", n.Name)
if widget.GetBool(n.value) {
log.Log(NOW, "BOX IS HORIZONTAL", n.progname)
} else {
log.Log(NOW, "BOX IS VERTICAL", n.Name)
log.Log(NOW, "BOX IS VERTICAL", n.progname)
}
case widget.Button:
n.doUserEvent()

View File

@ -14,7 +14,7 @@ func catchActionChannel() {
log.Log(NOW, "catchActionChannel() for loop")
select {
case a := <-pluginChan:
log.Log(NOW, "catchActionChannel() SELECT widget id =", a.WidgetId, a.Name)
log.Log(NOW, "catchActionChannel() SELECT widget id =", a.WidgetId, a.ProgName)
log.Log(NOW, "catchActionChannel() STUFF", a.WidgetId, a.ActionType, a.WidgetType)
muAction.Lock()
doAction(&a)

View File

@ -56,7 +56,7 @@ func (n *node) showButtons() {
}
func (n *node) dumpWidget(pad string) {
log.Log(NOW, "node:", pad, n.WidgetId, ",", n.WidgetType, ",", n.Name)
log.Log(NOW, "node:", pad, n.WidgetId, ",", n.WidgetType, ",", n.progname)
}
var depth int = 0

View File

@ -19,10 +19,10 @@ func initWidget(n *node) *guiWidget {
}
if (n.WidgetType == widget.Box) {
if (n.B) {
n.horizontal = true
if (n.direction == widget.Horizontal) {
// n.horizontal = true
} else {
n.horizontal = false
// n.horizontal = false
}
}