summaryrefslogtreecommitdiff
path: root/toolkit/gocui
diff options
context:
space:
mode:
Diffstat (limited to 'toolkit/gocui')
-rw-r--r--toolkit/gocui/click.go14
-rw-r--r--toolkit/gocui/debug.go9
-rw-r--r--toolkit/gocui/help.go1
-rw-r--r--toolkit/gocui/keybindings.go14
-rw-r--r--toolkit/gocui/main.go28
-rw-r--r--toolkit/gocui/place.go16
-rw-r--r--toolkit/gocui/showStdout.go10
-rw-r--r--toolkit/gocui/structs.go6
-rw-r--r--toolkit/gocui/tab.go16
-rw-r--r--toolkit/gocui/view.go50
10 files changed, 91 insertions, 73 deletions
diff --git a/toolkit/gocui/click.go b/toolkit/gocui/click.go
index cb58bc3..7c9ab24 100644
--- a/toolkit/gocui/click.go
+++ b/toolkit/gocui/click.go
@@ -93,8 +93,8 @@ func (n *node) doWidgetClick() {
log("doWidgetClick()", n.Name)
redoWindows(0,0)
case toolkit.Flag:
- // me.rootNode.redoColor(true)
- me.rootNode.dumpTree(true)
+ log("doWidgetClick() FLAG widget name =", n.Name)
+ log("doWidgetClick() if this is the dropdown menu, handle it here?")
case toolkit.Window:
if (me.currentWindow == n) {
return
@@ -155,7 +155,13 @@ func (n *node) doWidgetClick() {
}
n.doUserEvent()
case toolkit.Grid:
- n.placeGrid(n.tk.size.w0, n.tk.size.h0)
+ newR := n.realGocuiSize()
+
+ // w,h := n.logicalSize()
+ // w := newR.w1 - newR.w0
+ // h := newR.h1 - newR.h0
+
+ n.placeGrid(newR.w0, newR.h0)
n.showWidgets()
case toolkit.Box:
// w.showWidgetPlacement(logNow, "drawTree()")
@@ -267,12 +273,14 @@ func click(g *gocui.Gui, v *gocui.View) error {
}
if _, err := g.SetCurrentView(v.Name()); err != nil {
+ log(logNow, "click() END err =", err)
return err
}
log(logVerbose, "click() END")
return nil
}
+
func findUnderMouse() *node {
var found *node
var widgets []*node
diff --git a/toolkit/gocui/debug.go b/toolkit/gocui/debug.go
index 3ea31b0..7512c1e 100644
--- a/toolkit/gocui/debug.go
+++ b/toolkit/gocui/debug.go
@@ -10,7 +10,7 @@ func (n *node) dumpTree(draw bool) {
if (w == nil) {
return
}
- n.showWidgetPlacement(logNow, "Tree:")
+ n.showWidgetPlacement(logNow, "dumpTree()")
for _, child := range n.children {
child.dumpTree(draw)
@@ -33,13 +33,12 @@ func (n *node) showWidgetPlacement(b bool, s string) {
pId = n.parent.WidgetId
}
s1 = fmt.Sprintf("(wId,pId)=(%2d,%2d) ", n.WidgetId, pId)
- s1 += fmt.Sprintf("size=(%2d,%2d)(%2d,%2d,%2d,%2d)",
- w.size.Width(), w.size.Height(),
- w.size.w0, w.size.h0, w.size.w1, w.size.h1)
if n.Visible() {
s1 += fmt.Sprintf("gocui=(%2d,%2d)(%2d,%2d,%2d,%2d)",
w.gocuiSize.Width(), w.gocuiSize.Height(),
w.gocuiSize.w0, w.gocuiSize.h0, w.gocuiSize.w1, w.gocuiSize.h1)
+ } else {
+ s1 += fmt.Sprintf(" ")
}
if (n.parent != nil) {
if (n.parent.WidgetType == toolkit.Grid) {
@@ -50,7 +49,7 @@ func (n *node) showWidgetPlacement(b bool, s string) {
}
func (n *node) dumpWidget(pad string) {
- log(true, "node:", pad, n.WidgetId, "At(", n.AtW, n.AtH, ") ,", n.WidgetType, ",", n.Name)
+ log(true, "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/toolkit/gocui/help.go b/toolkit/gocui/help.go
index 6113257..82d5cc5 100644
--- a/toolkit/gocui/help.go
+++ b/toolkit/gocui/help.go
@@ -19,6 +19,7 @@ var helpText []string = []string{"KEYBINDINGS",
"r: redraw widgets",
"s/h: show/hide all widgets",
"L: list all widgets",
+ "M: list all widgets positions",
"q: quit()",
"p: panic()",
"o: show Stdout",
diff --git a/toolkit/gocui/keybindings.go b/toolkit/gocui/keybindings.go
index 658d09a..38ada12 100644
--- a/toolkit/gocui/keybindings.go
+++ b/toolkit/gocui/keybindings.go
@@ -29,6 +29,9 @@ func defaultKeybindings(g *gocui.Gui) error {
if err := g.SetKeybinding("", gocui.MouseLeft, gocui.ModMouseCtrl, ctrlDown); err != nil {
return err
}
+// if err := g.SetKeybinding(w.v.Name(), gocui.MouseLeft, gocui.ModNone, click); err != nil {
+// return err
+// }
/*
if err := g.SetKeybinding("", gocui.MouseLeft, gocui.ModNone, globalDown); err != nil {
return err
@@ -45,8 +48,6 @@ func addDebugKeys(g *gocui.Gui) {
// show debugging buttons
g.SetKeybinding("", 'd', gocui.ModNone,
func(g *gocui.Gui, v *gocui.View) error {
- log(logNow, "gocui.SetKeyBinding() dumpTree() START")
- // me.rootNode.dumpTree(true)
fakeStartWidth = me.FakeW
fakeStartHeight = me.TabH + me.FramePadH
if (showDebug) {
@@ -106,6 +107,13 @@ func addDebugKeys(g *gocui.Gui) {
return nil
})
+ // list all widgets with positions
+ g.SetKeybinding("", 'M', gocui.ModNone,
+ func(g *gocui.Gui, v *gocui.View) error {
+ me.rootNode.dumpTree(true)
+ return nil
+ })
+
// log to output window
g.SetKeybinding("", 'o', gocui.ModNone,
func(g *gocui.Gui, v *gocui.View) error {
@@ -136,7 +144,7 @@ func addDebugKeys(g *gocui.Gui) {
var a toolkit.Action
a.B = true
a.ActionType = toolkit.EnableDebug
- me.callback <- a
+ callback <- a
logInfo = true
logVerbose = true
} else {
diff --git a/toolkit/gocui/main.go b/toolkit/gocui/main.go
index 6214fcb..04e1255 100644
--- a/toolkit/gocui/main.go
+++ b/toolkit/gocui/main.go
@@ -17,7 +17,7 @@ func init() {
// init the config struct default values
Set(&me, "default")
- me.pluginChan = make(chan toolkit.Action)
+ pluginChan = make(chan toolkit.Action)
log(logNow, "Init() start pluginChan")
go catchActionChannel()
@@ -26,15 +26,6 @@ func init() {
sleep(.1) // probably not needed, but in here for now under development
}
-// this sets the channel to send user events back from the plugin
-func Callback(guiCallback chan toolkit.Action) {
- me.callback = guiCallback
-}
-
-func PluginChannel() chan toolkit.Action {
- return me.pluginChan
-}
-
/*
recieves requests from the program to do things like:
* add new widgets
@@ -46,7 +37,7 @@ func catchActionChannel() {
for {
log(logInfo, "catchActionChannel() infinite for() loop restarted select on channel")
select {
- case a := <-me.pluginChan:
+ case a := <-pluginChan:
if (me.baseGui == nil) {
// something went wrong initializing the gocui
log(logError,"ERROR: console did not initialize")
@@ -60,22 +51,29 @@ func catchActionChannel() {
func Exit() {
// TODO: what should actually happen here?
+ log(true, "Exit() here. doing standardExit()")
standardExit()
}
func standardExit() {
+ log(true, "standardExit() doing baseGui.Close()")
me.baseGui.Close()
+ log(true, "standardExit() doing outf.Close()")
outf.Close()
- setOutput(os.Stdout)
- sendBackQuit()
- sleep(.5)
+ // log(true, "standardExit() setOutput(os.Stdout)")
+ // setOutput(os.Stdout)
+ log(true, "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()
}
func sendBackQuit() {
// send 'Quit' back to the program (?)
var a toolkit.Action
a.ActionType = toolkit.UserQuit
- me.callback <- a
+ callback <- a
}
var outf *os.File
diff --git a/toolkit/gocui/place.go b/toolkit/gocui/place.go
index d02624e..f020257 100644
--- a/toolkit/gocui/place.go
+++ b/toolkit/gocui/place.go
@@ -9,8 +9,6 @@ func (n *node) placeBox(startW int, startH int) {
if (n.WidgetType != toolkit.Box) {
return
}
- n.tk.size.w0 = startW
- n.tk.size.h0 = startH
n.showWidgetPlacement(logNow, "boxS()")
newW := startW
@@ -18,7 +16,6 @@ func (n *node) placeBox(startW int, startH int) {
for _, child := range n.children {
child.placeWidgets(newW, newH)
// n.showWidgetPlacement(logNow, "boxS()")
- // w,h := child.logicalSize()
newR := child.realGocuiSize()
w := newR.w1 - newR.w0
h := newR.h1 - newR.h0
@@ -32,13 +29,10 @@ func (n *node) placeBox(startW int, startH int) {
newH += h
}
}
- // w,h := n.logicalSize()
- newR := n.realGocuiSize()
- w := newR.w1 - newR.w0
- h := newR.h1 - newR.h0
- n.tk.size.w1 = n.tk.size.w0 + w
- n.tk.size.h1 = n.tk.size.h0 + h
+ // just compute this every time?
+ // newR := n.realGocuiSize()
+
n.showWidgetPlacement(logNow, "boxE()")
}
@@ -75,7 +69,6 @@ func (n *node) placeWidgets(startW int, startH int) {
// now move all the children aka: run place() on them
for _, child := range n.children {
child.placeWidgets(newW, newH)
- // _,h := child.logicalSize()
newR := child.realGocuiSize()
// w := newR.w1 - newR.w0
h := newR.h1 - newR.h0
@@ -91,8 +84,6 @@ func (n *node) placeWidgets(startW int, startH int) {
func (n *node) placeGrid(startW int, startH int) {
w := n.tk
- w.size.w0 = startW
- w.size.h0 = startH
n.showWidgetPlacement(logInfo, "grid0:")
if (n.WidgetType != toolkit.Grid) {
return
@@ -100,7 +91,6 @@ func (n *node) placeGrid(startW int, startH int) {
// first compute the max sizes of the rows and columns
for _, child := range n.children {
- // childW, childH := child.logicalSize()
newR := child.realGocuiSize()
childW := newR.w1 - newR.w0
childH := newR.h1 - newR.h0
diff --git a/toolkit/gocui/showStdout.go b/toolkit/gocui/showStdout.go
index f03dfef..34f7e7b 100644
--- a/toolkit/gocui/showStdout.go
+++ b/toolkit/gocui/showStdout.go
@@ -62,9 +62,9 @@ func makeOutputWidget(g *gocui.Gui, stringFromMouseClick string) *gocui.View {
}
v, err := g.View("msg")
if (v == nil) {
- log("this is supposed to happen. v == nil", err)
+ log("makeoutputwindow() this is supposed to happen. v == nil", err)
} else {
- log("msg != nil. WTF now? err =", err)
+ log("makeoutputwindow() msg != nil. WTF now? err =", err)
}
// help, err := g.SetView("help", maxX-32, 0, maxX-1, 13, 0)
@@ -72,16 +72,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("this is supposed to happen?", err)
+ log("makeoutputwindow() this is supposed to happen?", err)
}
if (err != nil) {
- log("create output window failed", err)
+ log("makeoutputwindow() create output window failed", err)
return nil
}
if (v == nil) {
- log("msg == nil. WTF now? err =", err)
+ log("makeoutputwindow() msg == nil. WTF now? err =", err)
return nil
} else {
me.logStdout.tk.v = v
diff --git a/toolkit/gocui/structs.go b/toolkit/gocui/structs.go
index c61e7ad..ff97d23 100644
--- a/toolkit/gocui/structs.go
+++ b/toolkit/gocui/structs.go
@@ -15,7 +15,7 @@ import (
"sync"
"strings"
"github.com/awesome-gocui/gocui"
- "git.wit.org/wit/gui/toolkit"
+// "git.wit.org/wit/gui/toolkit"
)
// It's probably a terrible idea to call this 'me'
@@ -40,12 +40,14 @@ type config struct {
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
callback chan toolkit.Action
// this is the channel we get requests to make widgets
pluginChan chan toolkit.Action
+ */
// When the widget has a frame, like a button, it adds 2 lines runes on each side
// so you need 3 char spacing in each direction to not have them overlap
@@ -117,7 +119,7 @@ type guiWidget struct {
// the logical size of the widget
// For example, 40x12 would be the center of a normal terminal
- size rectType
+ // size rectType
// the actual gocui display view of this widget
// sometimes this isn't visible like with a Box or Grid
diff --git a/toolkit/gocui/tab.go b/toolkit/gocui/tab.go
index 3451e5c..90c2d1a 100644
--- a/toolkit/gocui/tab.go
+++ b/toolkit/gocui/tab.go
@@ -36,17 +36,13 @@ func (n *node) gocuiSetWH(sizeW, sizeH int) {
}
if tk.frame {
- tk.size.w0 = sizeW
- tk.size.h0 = sizeH
- tk.gocuiSize.w0 = tk.size.w0
- tk.gocuiSize.h0 = tk.size.h0
+ tk.gocuiSize.w0 = sizeW
+ tk.gocuiSize.h0 = sizeH
tk.gocuiSize.w1 = tk.gocuiSize.w0 + w + me.FramePadW
tk.gocuiSize.h1 = tk.gocuiSize.h0 + h + me.FramePadH
} else {
- tk.size.w0 = sizeW - 1
- tk.size.h0 = sizeH - 1
- tk.gocuiSize.w0 = tk.size.w0
- tk.gocuiSize.h0 = tk.size.h0
+ tk.gocuiSize.w0 = sizeW - 1
+ tk.gocuiSize.h0 = sizeH - 1
tk.gocuiSize.w1 = tk.gocuiSize.w0 + w + 1
tk.gocuiSize.h1 = tk.gocuiSize.h0 + h + 1
}
@@ -73,8 +69,6 @@ func redoWindows(nextW int, nextH int) {
n.hasTabs = false
}
- w.size.w0 = nextW
- w.size.h0 = nextH
n.gocuiSetWH(nextW, nextH)
n.deleteView()
n.showView()
@@ -98,8 +92,6 @@ func (p *node) redoTabs(nextW int, nextH int) {
w := n.tk
w.frame = true
- w.size.w0 = nextW
- w.size.h0 = nextH
n.gocuiSetWH(nextW, nextH)
n.deleteView()
// setCurrentTab(n)
diff --git a/toolkit/gocui/view.go b/toolkit/gocui/view.go
index 3baeb66..e69bf7c 100644
--- a/toolkit/gocui/view.go
+++ b/toolkit/gocui/view.go
@@ -22,14 +22,14 @@ func splitLines(s string) []string {
func (n *node) textResize() {
w := n.tk
- var width, height int
+ var width, height int = 0, 0
for i, s := range splitLines(n.Text) {
log(logNow, "textResize() len =", len(s), i, s)
if (width < len(s)) {
width = len(s)
}
- height = i
+ height += 1
}
w.gocuiSize.w1 = w.gocuiSize.w0 + width + me.FramePadW
w.gocuiSize.h1 = w.gocuiSize.h0 + height + me.FramePadH
@@ -81,13 +81,23 @@ func (n *node) showView() {
func (n *node) recreateView() {
var err error
w := n.tk
+ log(logError, "recreateView() START", n.WidgetType, n.Name)
if (me.baseGui == nil) {
- log(logError, "showView() ERROR: me.baseGui == nil", w)
+ log(logError, "recreateView() ERROR: me.baseGui == nil", w)
return
}
+
+ // this deletes the button from gocui
me.baseGui.DeleteView(w.cuiName)
w.v = nil
+ if (n.Name == "CLOUDFLARE_EMAIL") {
+ n.showWidgetPlacement(logNow, "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)
+ }
+
a := w.gocuiSize.w0
b := w.gocuiSize.h0
c := w.gocuiSize.w1
@@ -95,23 +105,33 @@ func (n *node) recreateView() {
w.v, err = me.baseGui.SetView(w.cuiName, a, b, c, d, 0)
if err == nil {
- n.showWidgetPlacement(logError, "drawView()")
- log(logError, "drawView() internal plugin error err = nil")
+ n.showWidgetPlacement(logError, "recreateView()")
+ log(logError, "recreateView() internal plugin error err = nil")
return
}
if !errors.Is(err, gocui.ErrUnknownView) {
- n.showWidgetPlacement(logError, "drawView()")
- log(logError, "drawView() internal plugin error error.IS()", err)
+ n.showWidgetPlacement(logError, "recreateView()")
+ log(logError, "recreateView() internal plugin error error.IS()", err)
return
}
+ // this sets up the keybinding for the name of the window
+ // does this really need to be done? I think we probably already
+ // know everything about where all the widgets are so we could bypass
+ // the gocui package and just handle all the mouse events internally here (?)
+ // for now, the w.v.Name is a string "1", "2", "3", etc from the widgetId
+
+ // set the binding for this gocui view now that it has been created
+ // gocui handles overlaps of views so it will run on the view that is clicked on
me.baseGui.SetKeybinding(w.v.Name(), gocui.MouseLeft, gocui.ModNone, click)
+ // this actually sends the text to display to gocui
w.v.Wrap = true
w.v.Frame = w.frame
w.v.Clear()
fmt.Fprint(w.v, n.Text)
- n.showWidgetPlacement(logNow, "Window: " + n.Text)
+ // n.showWidgetPlacement(logNow, "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
if (w.color != nil) {
@@ -121,6 +141,11 @@ func (n *node) recreateView() {
w.v.SelFgColor = w.color.selFg
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.dumpTree(true)
+ }
+ log(logError, "recreateView() END")
}
func (n *node) hideWidgets() {
@@ -167,13 +192,8 @@ func (n *node) showWidgets() {
if (w.isFake) {
// don't display by default
} else {
- // if n.IsCurrent() {
- n.showWidgetPlacement(logInfo, "current:")
- n.showView()
- // } else {
- // n.showWidgetPlacement(logInfo, "not:")
- // w.drawView()
- // }
+ n.showWidgetPlacement(logInfo, "current:")
+ n.showView()
}
for _, child := range n.children {
child.showWidgets()