summaryrefslogtreecommitdiff
path: root/toolkit/gocui
diff options
context:
space:
mode:
authorJeff Carr <[email protected]>2023-12-14 10:36:56 -0600
committerJeff Carr <[email protected]>2023-12-14 10:36:56 -0600
commit282119d970faed3f8a60d5105a2f26ee14681ff4 (patch)
tree1680731c899f0e147487b9ba4d50ace2f3e96eb1 /toolkit/gocui
parent9d075afb1df62276dea06be4a188eaee8fc69420 (diff)
tabs, windows + gocui dropdown menu (almost)
dropdown menu figures out what text was clicked dropdown menu movement changes line colors dropdown menus force user to select a response accidentally committed a binary tab selection works tab and window views almost working tabs and windows almost working window widgets selection works better color handling using gocui view.Visable flag removal of old color setting code still need an artificial delay for andlabs SetText() catching more 'nil' errors fixed the stupid duplicate tab problem in andlabs figured out how andlabs had a tab/box mess works on more than one domain builds and runs again debugging double tabs in andlabs gui GO111MODULE compile notes code reorg further improvements example cloudflare app does first successful dns update add NewEntryLine() for single line entry boxes Signed-off-by: Jeff Carr <[email protected]>
Diffstat (limited to 'toolkit/gocui')
-rw-r--r--toolkit/gocui/Makefile4
-rw-r--r--toolkit/gocui/add.go13
-rw-r--r--toolkit/gocui/click.go169
-rw-r--r--toolkit/gocui/color.go143
-rw-r--r--toolkit/gocui/common.go97
-rw-r--r--toolkit/gocui/gocui.go2
-rw-r--r--toolkit/gocui/help.go10
-rw-r--r--toolkit/gocui/keybindings.go27
-rw-r--r--toolkit/gocui/mouse.go66
-rw-r--r--toolkit/gocui/showStdout.go1
-rw-r--r--toolkit/gocui/structs.go21
-rw-r--r--toolkit/gocui/tab.go4
-rw-r--r--toolkit/gocui/view.go46
13 files changed, 420 insertions, 183 deletions
diff --git a/toolkit/gocui/Makefile b/toolkit/gocui/Makefile
index 6c4f7d5..4f2a6ee 100644
--- a/toolkit/gocui/Makefile
+++ b/toolkit/gocui/Makefile
@@ -2,10 +2,10 @@ all: plugin
ldd ../gocui.so
goget:
- GO111MODULE="off" go get -v -t -u
+ go get -v -t -u
plugin:
- GO111MODULE="off" go build -v -x -buildmode=plugin -o ../gocui.so
+ go build -v -x -buildmode=plugin -o ../gocui.so
objdump:
objdump -t ../gocui.so |less
diff --git a/toolkit/gocui/add.go b/toolkit/gocui/add.go
index 97d65d3..446d70c 100644
--- a/toolkit/gocui/add.go
+++ b/toolkit/gocui/add.go
@@ -31,29 +31,40 @@ func (n *node) addWidget() {
switch n.WidgetType {
case toolkit.Root:
log(logInfo, "setStartWH() rootNode w.id =", n.WidgetId, "w.name", n.Name)
+ nw.color = &colorRoot
n.setFake()
return
case toolkit.Flag:
+ nw.color = &colorFlag
n.setFake()
return
case toolkit.Window:
nw.frame = false
- redoWindows(0,0)
+ nw.color = &colorWindow
+ // redoWindows(0,0)
return
case toolkit.Tab:
+ nw.color = &colorTab
+ // redoWindows(0,0)
return
+ case toolkit.Button:
+ nw.color = &colorButton
case toolkit.Box:
+ nw.color = &colorBox
nw.isFake = true
n.setFake()
return
case toolkit.Grid:
+ nw.color = &colorGrid
nw.isFake = true
n.setFake()
return
case toolkit.Group:
+ nw.color = &colorGroup
nw.frame = false
return
case toolkit.Label:
+ nw.color = &colorLabel
nw.frame = false
return
default:
diff --git a/toolkit/gocui/click.go b/toolkit/gocui/click.go
index 380b0a3..cb58bc3 100644
--- a/toolkit/gocui/click.go
+++ b/toolkit/gocui/click.go
@@ -1,17 +1,23 @@
package main
import (
+ "fmt"
"github.com/awesome-gocui/gocui"
"git.wit.org/wit/gui/toolkit"
)
// set isCurrent = false everywhere
-func UnsetCurrent(n *node) {
+func unsetCurrent(n *node) {
w := n.tk
w.isCurrent = false
+ if n.WidgetType == toolkit.Tab {
+ // n.tk.color = &colorTab
+ // n.setColor()
+ }
+
for _, child := range n.children {
- UnsetCurrent(child)
+ unsetCurrent(child)
}
}
@@ -22,7 +28,14 @@ func (n *node) updateCurrent() {
log("updateCurrent()", n.Name)
if n.WidgetType == toolkit.Tab {
if n.IsCurrent() {
+ // n.tk.color = &colorActiveT
+ n.setColor(&colorActiveT)
+ n.hideView()
+ n.showView()
setCurrentTab(n)
+ } else {
+ // n.tk.color = &colorTab
+ // n.setColor()
}
return
}
@@ -47,7 +60,7 @@ func setCurrentWindow(n *node) {
if n.WidgetType != toolkit.Window {
return
}
- UnsetCurrent(me.rootNode)
+ unsetCurrent(me.rootNode)
if n.hasTabs {
// set isCurrent = true on the first tab
@@ -66,7 +79,7 @@ func setCurrentTab(n *node) {
if n.WidgetType != toolkit.Tab {
return
}
- UnsetCurrent(me.rootNode)
+ unsetCurrent(me.rootNode)
w.isCurrent = true
p := n.parent.tk
p.isCurrent = true
@@ -83,14 +96,51 @@ func (n *node) doWidgetClick() {
// me.rootNode.redoColor(true)
me.rootNode.dumpTree(true)
case toolkit.Window:
- me.rootNode.hideWidgets()
+ if (me.currentWindow == n) {
+ return
+ }
+ if (me.currentWindow != nil) {
+ unsetCurrent(me.currentWindow)
+ me.currentWindow.setColor(&colorWindow)
+ me.currentWindow.hideWidgets()
+ }
+ n.hideWidgets()
+ me.currentWindow = n
+ // setCurrentWindow(n) // probably delete this
+ n.setColor(&colorActiveW)
n.redoTabs(me.TabW, me.TabH)
+ for _, child := range n.children {
+ if (child.currentTab == true) {
+ log(true, "FOUND CURRENT TAB", child.Name)
+ setCurrentTab(child)
+ child.placeWidgets(me.RawW, me.RawH)
+ child.showWidgets()
+ return
+ }
+ }
+ /* FIXME: redo this
if ! n.hasTabs {
- setCurrentWindow(n)
- n.placeWidgets(me.RawW, me.RawH)
- n.showWidgets()
}
+ */
case toolkit.Tab:
+ if (n.IsCurrent()) {
+ return // do nothing if you reclick on the already selected tab
+ }
+ // find the window and disable the active tab
+ p := n.parent
+ if (p != nil) {
+ p.hideWidgets()
+ p.redoTabs(me.TabW, me.TabH)
+ unsetCurrent(p)
+ for _, child := range p.children {
+ if child.WidgetType == toolkit.Tab {
+ child.setColor(&colorTab)
+ n.currentTab = false
+ }
+ }
+ }
+ n.currentTab = true
+ n.setColor(&colorActiveT)
setCurrentTab(n)
n.placeWidgets(me.RawW, me.RawH)
n.showWidgets()
@@ -118,6 +168,50 @@ func (n *node) doWidgetClick() {
n.toggleTree()
case toolkit.Button:
n.doUserEvent()
+ case toolkit.Dropdown:
+ log(true, "do the dropdown here")
+ if (me.ddview == nil) {
+ me.ddview = addDropdown()
+ tk := me.ddview.tk
+ tk.gocuiSize.w0 = 20
+ tk.gocuiSize.w1 = 40
+ tk.gocuiSize.h0 = 10
+ tk.gocuiSize.h1 = 25
+ tk.v, _ = me.baseGui.SetView("ddview",
+ tk.gocuiSize.w0,
+ tk.gocuiSize.h0,
+ tk.gocuiSize.w1,
+ tk.gocuiSize.h1, 0)
+ if (tk.v == nil) {
+ return
+ }
+ tk.v.Wrap = true
+ tk.v.Frame = true
+ tk.v.Clear()
+ fmt.Fprint(tk.v, "example.com\nwit.org\nwit.com")
+ me.ddview.SetVisible(true)
+ return
+ }
+ log(true, "doWidgetClick() visible =", me.ddview.Visible())
+ if (me.ddview.Visible()) {
+ me.ddview.SetVisible(false)
+ me.baseGui.DeleteView("ddview")
+ me.ddview.tk.v = nil
+ } else {
+ var dnsList string
+ for i, s := range n.vals {
+ log(logNow, "AddText()", n.Name, i, s)
+ dnsList += s + "\n"
+ }
+ me.ddNode = n
+ log(logNow, "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)
+ }
default:
}
}
@@ -162,26 +256,15 @@ func click(g *gocui.Gui, v *gocui.View) error {
n := findUnderMouse()
if (n != nil) {
log(logNow, "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")
+ me.ddClicked = true
+ }
n.doWidgetClick()
} else {
log(logNow, "click() could not find node name =", v.Name())
}
- /*
- i, err := strconv.Atoi(v.Name())
- if (err != nil) {
- log(logError, "click() Can't find widget. error =", err)
- } else {
- log(logVerbose, "click() ok v.Name() =", v.Name())
- n := me.rootNode.findWidgetId(i)
- if (n == nil) {
- log(logError, "click() CANT FIND VIEW in binary tree. v.Name =", v.Name())
- return nil
- }
- log(logNow, "click() Found widget =", n.WidgetId, n.Name, ",", n.Text)
- n.doWidgetClick()
- return nil
- }
- */
if _, err := g.SetCurrentView(v.Name()); err != nil {
return err
@@ -207,6 +290,17 @@ func findUnderMouse() *node {
found = n
}
}
+ if (n == me.ddview) {
+ log(true, "findUnderMouse() found ddview")
+ if n.Visible() {
+ log(true, "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")
+ }
+ }
for _, child := range n.children {
f(child)
@@ -217,7 +311,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, "ctrlDown() FOUND")
+ n.showWidgetPlacement(logNow, "findUnderMouse() FOUND")
}
return found
}
@@ -228,27 +322,6 @@ func ctrlDown(g *gocui.Gui, v *gocui.View) error {
// var widgets []*node
// var f func (n *node)
found = findUnderMouse()
- /*
- w, h := g.MousePosition()
-
- // find buttons that are below where the mouse button click
- f = func(n *node) {
- widget := n.tk
- // ignore widgets that are not visible
- if n.Visible() {
- if ((widget.gocuiSize.w0 <= w) && (w <= widget.gocuiSize.w1) &&
- (widget.gocuiSize.h0 <= h) && (h <= widget.gocuiSize.h1)) {
- widgets = append(widgets, n)
- found = n
- }
- }
-
- for _, child := range n.children {
- f(child)
- }
- }
- f(me.rootNode)
- */
if (me.ctrlDown == nil) {
setupCtrlDownWidget()
me.ctrlDown.Text = found.Name
@@ -266,9 +339,9 @@ func ctrlDown(g *gocui.Gui, v *gocui.View) error {
cd.gocuiSize.w1 = newR.w1
cd.gocuiSize.h1 = newR.h1
if me.ctrlDown.Visible() {
- me.ctrlDown.deleteView()
+ me.ctrlDown.hideView()
} else {
- me.ctrlDown.updateView()
+ me.ctrlDown.showView()
}
me.ctrlDown.showWidgetPlacement(logNow, "ctrlDown:")
return nil
diff --git a/toolkit/gocui/color.go b/toolkit/gocui/color.go
index 5dbed05..4c2ea76 100644
--- a/toolkit/gocui/color.go
+++ b/toolkit/gocui/color.go
@@ -3,86 +3,85 @@ package main
import (
"math/rand"
"github.com/awesome-gocui/gocui"
- "git.wit.org/wit/gui/toolkit"
)
-// ColorBlack ColorRed ColorGreen ColorYellow ColorBlue ColorMagenta ColorCyan ColorWhite
-// gocui.GetColor("#FFAA55") // Dark Purple
-func (n *node) setDefaultWidgetColor() {
- w := n.tk
- log(logInfo, "setDefaultWidgetColor() on", n.WidgetType, n.Name)
- v, _ := me.baseGui.View(w.cuiName)
- if (v == nil) {
- log(logError, "setDefaultWidgetColor() failed on view == nil")
- return
- }
- sleep(.05)
- // v.BgColor = gocui.GetColor("#FFAA55") // Dark Purple
- // v.BgColor = gocui.GetColor("#88AA55") // heavy purple
- // v.BgColor = gocui.GetColor("#111111") // crazy red
- // v.BgColor = gocui.GetColor("#FF9911") // heavy red
- // v.SelBgColor = gocui.GetColor("#FFEE11") // blood red
+//w.v.SelBgColor = gocui.ColorCyan
+//color.go: w.v.SelFgColor = gocui.ColorBlack
+//color.go: w.v.BgColor = gocui.ColorGreen
- // v.BgColor = gocui.GetColor("#55AAFF") // super light grey
- // v.BgColor = gocui.GetColor("#FFC0CB") // 'w3c pink' yellow
- switch n.WidgetType {
- case toolkit.Root:
- v.FrameColor = gocui.ColorRed
- v.BgColor = gocui.GetColor("#B0E0E6") // w3c 'powerder blue'
- case toolkit.Flag:
- v.FrameColor = gocui.ColorRed
- v.BgColor = gocui.GetColor("#B0E0E6") // w3c 'powerder blue'
- case toolkit.Window:
- v.FgColor = gocui.ColorCyan
- v.SelBgColor = gocui.ColorBlue
- v.FrameColor = gocui.ColorBlue
- case toolkit.Tab:
- v.SelBgColor = gocui.ColorBlue
- v.FrameColor = gocui.ColorBlue
- case toolkit.Button:
- v.BgColor = gocui.ColorWhite
- v.FrameColor = gocui.ColorGreen
- v.SelBgColor = gocui.ColorBlack
- v.SelFgColor = gocui.ColorGreen
- case toolkit.Label:
- v.BgColor = gocui.GetColor("#55AAFF") // super light grey
- v.SelBgColor = gocui.GetColor("#55AAFF") // super light grey
- case toolkit.Box:
- v.FrameColor = gocui.ColorRed
- // v.BgColor = gocui.GetColor("#FFC0CB") // 'w3c pink' yellow
- v.BgColor = gocui.GetColor("#DDDDDD") // light purple
- case toolkit.Grid:
- // v.FgColor = gocui.ColorCyan
- // v.SelBgColor = gocui.ColorBlue
- // v.FrameColor = gocui.ColorBlue
- case toolkit.Group:
- v.BgColor = gocui.GetColor("#55AAFF") // super light grey
- default:
- }
+type colorT struct {
+ frame gocui.Attribute
+ fg gocui.Attribute
+ bg gocui.Attribute
+ selFg gocui.Attribute
+ selBg gocui.Attribute
+ name string
}
-// SetColor("#FFAA55") // purple
-func (w *cuiWidget) SetColor(c string) {
- if (w.v == nil) {
- log(logError, "SetColor() failed on view == nil")
+var none gocui.Attribute = gocui.AttrNone
+var lightPurple gocui.Attribute = gocui.GetColor("#DDDDDD") // light purple
+var darkPurple gocui.Attribute = gocui.GetColor("#FFAA55") // Dark Purple
+var heavyPurple gocui.Attribute = gocui.GetColor("#88AA55") // heavy purple
+var powdererBlue gocui.Attribute = gocui.GetColor("#B0E0E6") // w3c 'powerder blue'
+var superLightGrey gocui.Attribute = gocui.GetColor("#55AAFF") // super light grey
+
+// Standard defined colors from gocui:
+// ColorBlack ColorRed ColorGreen ColorYellow ColorBlue ColorMagenta ColorCyan ColorWhite
+
+// v.BgColor = gocui.GetColor("#111111") // crazy red
+// v.BgColor = gocui.GetColor("#FF9911") // heavy red
+// v.SelBgColor = gocui.GetColor("#FFEE11") // blood red
+
+// v.BgColor = gocui.GetColor("#55AAFF") // super light grey
+// v.BgColor = gocui.GetColor("#FFC0CB") // 'w3c pink' yellow
+
+// Normal Text On mouseover
+// Widget Frame Text background Text background
+var colorWindow colorT = colorT{ none , gocui.ColorBlue, none , none , powdererBlue , "normal window"}
+var colorActiveW colorT = colorT{ none , none , powdererBlue , none , powdererBlue , "active window"}
+
+var colorTab colorT = colorT{gocui.ColorBlue, gocui.ColorBlue, none , none , powdererBlue , "normal tab"}
+var colorActiveT colorT = colorT{gocui.ColorBlue, none , powdererBlue , none , powdererBlue , "active tab"}
+
+var colorButton colorT = colorT{gocui.ColorGreen, none , gocui.ColorWhite, gocui.ColorGreen, gocui.ColorBlack, "normal button"}
+var colorLabel colorT = colorT{ none , none , superLightGrey , none , superLightGrey , "normal label"}
+var colorGroup colorT = colorT{ none , none , superLightGrey , none , superLightGrey , "normal group"}
+
+// widget debugging colors. these widgets aren't displayed unless you are debugging
+var colorRoot colorT = colorT{gocui.ColorRed , none , powdererBlue , none , gocui.ColorBlue, "debug root"}
+var colorFlag colorT = colorT{gocui.ColorRed , none , powdererBlue , none , gocui.ColorGreen, "debug flag"}
+var colorBox colorT = colorT{gocui.ColorRed , none , lightPurple , none , gocui.ColorCyan, "debug box"}
+var colorGrid colorT = colorT{gocui.ColorRed , none , lightPurple , none , gocui.ColorRed, "debug grid"}
+var colorNone colorT = colorT{ none , none , none , none , none , "debug none"}
+
+// actually sets the colors for the gocui element
+// the user will see the colors change when this runs
+// TODO: add black/white only flag for ttyS0
+// TODO: or fix kvm/qemu serial console & SIGWINCH.
+// TODO: and minicom and uboot and 5 million other things.
+// TODO: maybe enough of us could actually do that if we made it a goal.
+// TODO: start with riscv boards and fix it universally there
+// TODO: so just a small little 'todo' item here
+func (n *node) setColor(newColor *colorT) {
+ tk := n.tk
+ if (tk.color == newColor) {
+ // nothing to do since the colors have nto changed
return
}
- w.v.SelBgColor = gocui.ColorCyan
- w.v.SelFgColor = gocui.ColorBlack
- switch c {
- case "Green":
- w.v.BgColor = gocui.ColorGreen
- case "Purple":
- w.v.BgColor = gocui.GetColor("#FFAA55")
- case "Yellow":
- w.v.BgColor = gocui.ColorYellow
- case "Blue":
- w.v.BgColor = gocui.ColorBlue
- case "Red":
- w.v.BgColor = gocui.ColorRed
- default:
- w.v.BgColor = gocui.GetColor(c)
+ tk.color = newColor
+ if (tk.v == nil) {
+ return
+ }
+ if (tk.color == nil) {
+ log(true, "Set the node to color = nil")
+ tk.color = &colorNone
}
+ log(true, "Set the node to color =", tk.color.name)
+ n.recreateView()
+}
+
+func (n *node) setDefaultWidgetColor() {
+ n.showView()
}
func (n *node) setDefaultHighlight() {
diff --git a/toolkit/gocui/common.go b/toolkit/gocui/common.go
index 05de64b..d3de34c 100644
--- a/toolkit/gocui/common.go
+++ b/toolkit/gocui/common.go
@@ -98,6 +98,46 @@ func (n *node) findWidgetName(name string) *node {
return nil
}
+func (n *node) IsCurrent() bool {
+ w := n.tk
+ if (n.WidgetType == toolkit.Tab) {
+ return w.isCurrent
+ }
+ if (n.WidgetType == toolkit.Window) {
+ return w.isCurrent
+ }
+ if (n.WidgetType == toolkit.Root) {
+ return false
+ }
+ return n.parent.IsCurrent()
+}
+
+func (n *node) Visible() bool {
+ if (n == nil) {
+ return false
+ }
+ if (n.tk == nil) {
+ return false
+ }
+ if (n.tk.v == nil) {
+ return false
+ }
+ return n.tk.v.Visible
+}
+
+func (n *node) SetVisible(b bool) {
+ if (n == nil) {
+ return
+ }
+ if (n.tk == nil) {
+ return
+ }
+ if (n.tk.v == nil) {
+ return
+ }
+ n.tk.v.Visible = b
+}
+
func addNode(a *toolkit.Action) *node {
n := new(node)
n.WidgetType = a.WidgetType
@@ -143,42 +183,29 @@ func addNode(a *toolkit.Action) *node {
return n
}
-func (n *node) IsCurrent() bool {
- w := n.tk
- if (n.WidgetType == toolkit.Tab) {
- return w.isCurrent
- }
- if (n.WidgetType == toolkit.Window) {
- return w.isCurrent
- }
- if (n.WidgetType == toolkit.Root) {
- return false
- }
- return n.parent.IsCurrent()
-}
+func addDropdown() *node {
+ n := new(node)
+ n.WidgetType = toolkit.Flag
+ n.WidgetId = -2
+ n.ParentId = 0
-func (n *node) Visible() bool {
- if (n == nil) {
- return false
- }
- if (n.tk == nil) {
- return false
- }
- if (n.tk.v == nil) {
- return false
- }
- return n.tk.v.Visible
-}
+ // copy the data from the action message
+ n.Name = "DropBox"
+ n.Text = "DropBox text"
-func (n *node) SetVisible(b bool) {
- if (n == nil) {
- return
- }
- if (n.tk == nil) {
- return
- }
- if (n.tk.v == nil) {
- return
+ // store the internal toolkit information
+ n.tk = new(cuiWidget)
+ n.tk.frame = true
+
+ // set the name used by gocui to the id
+ n.tk.cuiName = "-1 dropbox"
+
+ n.tk.color = &colorFlag
+
+ // add this new widget on the binary tree
+ n.parent = me.rootNode
+ if n.parent != nil {
+ n.parent.children = append(n.parent.children, n)
}
- n.tk.v.Visible = b
+ return n
}
diff --git a/toolkit/gocui/gocui.go b/toolkit/gocui/gocui.go
index 85e6ea5..d2877d7 100644
--- a/toolkit/gocui/gocui.go
+++ b/toolkit/gocui/gocui.go
@@ -72,7 +72,7 @@ func dragOutputWindow() {
func setFrame(b bool) {
// TODO: figure out what this might be useful for
// what is this do? I made it just 2 lines for now. Is this useful for something?
- v := SetView("global", 15, 5, 80, 8, 10)
+ v := SetView("global", 5, 10, 5, 10, 0) // x0, x1, y1, y2, overlap
if (v == nil) {
log(logError, "setFrame() global failed")
}
diff --git a/toolkit/gocui/help.go b/toolkit/gocui/help.go
index 66719bb..6113257 100644
--- a/toolkit/gocui/help.go
+++ b/toolkit/gocui/help.go
@@ -14,7 +14,9 @@ import (
var helpText []string = []string{"KEYBINDINGS",
"",
- "d: show/hide debugging",
+ "?: toggle help",
+ "d: toggle debugging",
+ "r: redraw widgets",
"s/h: show/hide all widgets",
"L: list all widgets",
"q: quit()",
@@ -27,6 +29,12 @@ var helpText []string = []string{"KEYBINDINGS",
"",
}
+func hidehelplayout() {
+ me.baseGui.DeleteView("help")
+ // n.deleteView()
+ // child.hideFake()
+}
+
func helplayout() error {
g := me.baseGui
var err error
diff --git a/toolkit/gocui/keybindings.go b/toolkit/gocui/keybindings.go
index dbe1fe2..658d09a 100644
--- a/toolkit/gocui/keybindings.go
+++ b/toolkit/gocui/keybindings.go
@@ -22,6 +22,7 @@ func defaultKeybindings(g *gocui.Gui) error {
if err := g.SetKeybinding("", gocui.MouseRelease, gocui.ModNone, mouseUp); err != nil {
return err
}
+ // mouseDown() runs whenever you click on an unknown view (?)
if err := g.SetKeybinding("", gocui.MouseLeft, gocui.ModNone, mouseDown); err != nil {
return err
}
@@ -40,10 +41,8 @@ func defaultKeybindings(g *gocui.Gui) error {
return nil
}
-var showDebug bool = true
-
func addDebugKeys(g *gocui.Gui) {
- // dump all widget info to the log
+ // show debugging buttons
g.SetKeybinding("", 'd', gocui.ModNone,
func(g *gocui.Gui, v *gocui.View) error {
log(logNow, "gocui.SetKeyBinding() dumpTree() START")
@@ -63,9 +62,29 @@ func addDebugKeys(g *gocui.Gui) {
// display the help menu
g.SetKeybinding("", '?', gocui.ModNone,
func(g *gocui.Gui, v *gocui.View) error {
- helplayout()
+ if (showHelp) {
+ helplayout()
+ showHelp = false
+ } else {
+ me.baseGui.DeleteView("help")
+ showHelp = true
+ }
+ return nil
+ })
+
+ // redraw all the widgets
+ g.SetKeybinding("", 'r', gocui.ModNone,
+ func(g *gocui.Gui, v *gocui.View) error {
+ if (redoWidgets) {
+ redoWindows(0,0)
+ redoWidgets = false
+ } else {
+ me.rootNode.hideWidgets()
+ redoWidgets = true
+ }
return nil
})
+
// hide all widgets
g.SetKeybinding("", 'h', gocui.ModNone,
func(g *gocui.Gui, v *gocui.View) error {
diff --git a/toolkit/gocui/mouse.go b/toolkit/gocui/mouse.go
index dbe2c6d..64786ab 100644
--- a/toolkit/gocui/mouse.go
+++ b/toolkit/gocui/mouse.go
@@ -24,6 +24,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)
if vx, vy, _, _, err := g.ViewPosition("msg"); err == nil {
xOffset = initialMouseX - vx
yOffset = initialMouseY - vy
@@ -32,7 +33,58 @@ func msgDown(g *gocui.Gui, v *gocui.View) error {
return nil
}
+func hideDDview() error {
+ w, h := me.baseGui.MousePosition()
+ log(true, "hide dropdown menu() view msgMouseDown (w,h) =", w, h)
+ if (me.ddview == nil) {
+ return gocui.ErrUnknownView
+ }
+ if (me.ddview.tk.v == nil) {
+ return gocui.ErrUnknownView
+ }
+ me.ddview.SetVisible(false)
+ return nil
+}
+
+func showDDview() error {
+ w, h := me.baseGui.MousePosition()
+ log(true, "show dropdown menu() view msgMouseDown (w,h) =", w, h)
+ if (me.ddview == nil) {
+ return gocui.ErrUnknownView
+ }
+ if (me.ddview.tk.v == nil) {
+ return gocui.ErrUnknownView
+ }
+ me.ddview.SetVisible(true)
+ return nil
+}
+
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)
+ if (me.ddClicked) {
+ 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)
+
+ 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)
+ valsLen := len(me.ddNode.vals)
+ log(true, "mouseUp() value =", value, "valsLen =", valsLen)
+ log(true, "mouseUp() me.ddNode.vals =", me.ddNode.vals)
+ if ((value >= 0) && (value < valsLen)) {
+ str := me.ddNode.vals[value]
+ log(true, "mouseUp() value =", value, "str =", str)
+ }
+ }
+ }
+ /*
+ // if there is a drop down view active, treat it like a dialog box and close it
+ if (hideDDview() == nil) {
+ return nil
+ }
+ */
if msgMouseDown {
msgMouseDown = false
if movingMsg {
@@ -57,13 +109,25 @@ func mouseDown(g *gocui.Gui, v *gocui.View) error {
}
globalMouseDown = true
maxX, _ := g.Size()
- msg := fmt.Sprintf("Mouse really down at: %d,%d", mx, my) + "foo\n" + "bar\n"
+ test := findUnderMouse()
+ 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)
+ hideDDview()
+ } else {
+ log(true, "show DDview() Mouse really down at:", mx, my)
+ showDDview()
+ }
+ return nil
+ }
x := mx - len(msg)/2
if x < 0 {
x = 0
} 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)
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/toolkit/gocui/showStdout.go b/toolkit/gocui/showStdout.go
index 22e95d3..f03dfef 100644
--- a/toolkit/gocui/showStdout.go
+++ b/toolkit/gocui/showStdout.go
@@ -24,6 +24,7 @@ func showMsg(g *gocui.Gui, v *gocui.View) error {
var l string
var err error
+ log(true, "showMsg() v.name =", v.Name())
if _, err := g.SetCurrentView(v.Name()); err != nil {
return err
}
diff --git a/toolkit/gocui/structs.go b/toolkit/gocui/structs.go
index 06a2266..05df963 100644
--- a/toolkit/gocui/structs.go
+++ b/toolkit/gocui/structs.go
@@ -21,14 +21,24 @@ import (
// It's probably a terrible idea to call this 'me'
var me config
+var showDebug bool = true
+var showHelp bool = true
+var redoWidgets bool = true
+
+// This is the window that is currently active
+var currentWindow *node
+
type config struct {
baseGui *gocui.Gui // the main gocui handle
rootNode *node // the base of the binary tree. it should have id == 0
ctrlDown *node // shown if you click the mouse when the ctrl key is pressed
-// current *cuiWidget // this is the current tab or window to show
+ currentWindow *node // this is the current tab or window to show
logStdout *node // where to show STDOUT
helpLabel *gocui.View
+ ddview *node // the gocui view to select dropdrown lists
+ ddClicked bool // the dropdown menu view was clicked
+ ddNode *node // the dropdown menu is for this widget
// this is the channel we send user events like
// mouse clicks or keyboard events back to the program
@@ -123,6 +133,7 @@ type node struct {
horizontal bool `default:false`
hasTabs bool // does the window have tabs?
+ currentTab bool // the visible tab
// the internal plugin toolkit structure
tk *cuiWidget
@@ -152,7 +163,7 @@ type cuiWidget struct {
size rectType
// the actual gocui display view of this widget
- // sometimes this isn't visable like with a Box or Grid
+ // sometimes this isn't visible like with a Box or Grid
gocuiSize rectType
isCurrent bool // is this the currently displayed Window or Tab?
@@ -164,6 +175,12 @@ type cuiWidget struct {
tainted bool
frame bool
+
+ // for a window, this is currently selected tab
+ selectedTab *node
+
+ // what color to use
+ color *colorT
}
// from the gocui devs:
diff --git a/toolkit/gocui/tab.go b/toolkit/gocui/tab.go
index 60ee6b3..d910552 100644
--- a/toolkit/gocui/tab.go
+++ b/toolkit/gocui/tab.go
@@ -103,6 +103,10 @@ func (p *node) redoTabs(nextW int, nextH int) {
n.gocuiSetWH(nextW, nextH)
n.deleteView()
// setCurrentTab(n)
+ // if (len(w.cuiName) < 4) {
+ // w.cuiName = "abcd"
+ // }
+
n.showView()
sizeW := w.Width() + me.TabPadW
diff --git a/toolkit/gocui/view.go b/toolkit/gocui/view.go
index e2c76aa..3baeb66 100644
--- a/toolkit/gocui/view.go
+++ b/toolkit/gocui/view.go
@@ -36,7 +36,12 @@ func (n *node) textResize() {
n.showWidgetPlacement(logNow, "textResize()")
}
+func (n *node) hideView() {
+ n.SetVisible(false)
+}
+
// display's the text of the widget in gocui
+// will create a new gocui view if there isn't one or if it has been moved
func (n *node) showView() {
var err error
w := n.tk
@@ -46,31 +51,34 @@ func (n *node) showView() {
w.cuiName = strconv.Itoa(n.WidgetId)
}
+ // if the gocui element doesn't exist, create it
if (w.v == nil) {
- n.updateView()
+ n.recreateView()
}
x0, y0, x1, y1, err := me.baseGui.ViewPosition(w.cuiName)
log(logInfo, "showView() w.v already defined for widget", n.Name, err)
+
+ // if the gocui element has changed where it is supposed to be on the screen
+ // recreate it
if (x0 != w.gocuiSize.w0) || (y0 != w.gocuiSize.h0) {
log(logError, "showView() w.v.w0 != x0", n.Name, w.gocuiSize.w0, x0)
log(logError, "showView() w.v.h0 != y0", n.Name, w.gocuiSize.h0, y0)
- n.updateView()
+ n.recreateView()
return
}
if (x1 != w.gocuiSize.w1) || (y1 != w.gocuiSize.h1) {
log(logError, "showView() w.v.w1 != x1", n.Name, w.gocuiSize.w1, x1)
log(logError, "showView() w.v.h1 != y1", n.Name, w.gocuiSize.h1, y1)
- n.updateView()
+ n.recreateView()
return
}
- if (w.v.Visible == false) {
- log(logInfo, "showView() w.v.Visible set to true ", n.Name)
- w.v.Visible = true
- }
+ n.SetVisible(true)
}
-func (n *node) updateView() {
+// create or recreate the gocui widget visible
+// deletes the old view if it exists and recreates it
+func (n *node) recreateView() {
var err error
w := n.tk
if (me.baseGui == nil) {
@@ -105,8 +113,14 @@ func (n *node) updateView() {
fmt.Fprint(w.v, n.Text)
n.showWidgetPlacement(logNow, "Window: " + n.Text)
- n.setDefaultHighlight()
- n.setDefaultWidgetColor()
+ // if you don't do this here, it will be black & white only
+ if (w.color != nil) {
+ w.v.FrameColor = w.color.frame
+ w.v.FgColor = w.color.fg
+ w.v.BgColor = w.color.bg
+ w.v.SelFgColor = w.color.selFg
+ w.v.SelBgColor = w.color.selBg
+ }
}
func (n *node) hideWidgets() {
@@ -119,7 +133,7 @@ func (n *node) hideWidgets() {
case toolkit.Box:
case toolkit.Grid:
default:
- n.deleteView()
+ n.hideView()
}
for _, child := range n.children {
child.hideWidgets()
@@ -129,7 +143,7 @@ func (n *node) hideWidgets() {
func (n *node) hideFake() {
w := n.tk
if (w.isFake) {
- n.deleteView()
+ n.hideView()
}
for _, child := range n.children {
child.hideFake()
@@ -153,13 +167,13 @@ func (n *node) showWidgets() {
if (w.isFake) {
// don't display by default
} else {
- if n.IsCurrent() {
+ // if n.IsCurrent() {
n.showWidgetPlacement(logInfo, "current:")
n.showView()
- } else {
- n.showWidgetPlacement(logInfo, "not:")
+ // } else {
+ // n.showWidgetPlacement(logInfo, "not:")
// w.drawView()
- }
+ // }
}
for _, child := range n.children {
child.showWidgets()