wrapping my head around this code again
This commit is contained in:
parent
11465e4043
commit
75a5c7bf72
2
Makefile
2
Makefile
|
@ -4,7 +4,7 @@ BUILDTIME = $(shell date +%Y.%m.%d)
|
||||||
all: clean gocui.so
|
all: clean gocui.so
|
||||||
@#ldd gocui.so
|
@#ldd gocui.so
|
||||||
|
|
||||||
gocui.so: view.pb.go goimports
|
gocui.so: goimports
|
||||||
GO111MODULE=off go build -v -work -buildmode=plugin -o gocui.so \
|
GO111MODULE=off go build -v -work -buildmode=plugin -o gocui.so \
|
||||||
-ldflags "-X main.VERSION=${VERSION} -X main.BUILDTIME=${BUILDTIME} -X gui.GUIVERSION=${VERSION}"
|
-ldflags "-X main.VERSION=${VERSION} -X main.BUILDTIME=${BUILDTIME} -X gui.GUIVERSION=${VERSION}"
|
||||||
|
|
||||||
|
|
17
dropdown.go
17
dropdown.go
|
@ -10,6 +10,17 @@ import (
|
||||||
"go.wit.com/widget"
|
"go.wit.com/widget"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// dropdowns don't exist so this is an attempt to pretend they exist
|
||||||
|
// by having a fake window view in gocui that appears with the dropdown
|
||||||
|
// items. by detecting where the user clicks, we should be
|
||||||
|
// able to set the text of the button to that value (and
|
||||||
|
// rezise it.
|
||||||
|
|
||||||
|
// the thing is this is so damned complicated because it
|
||||||
|
// is very hard to debug this. thanks to the floating on
|
||||||
|
// screen debugging output I might be able to figure it
|
||||||
|
// it out now. maybe. notsure.
|
||||||
|
|
||||||
func makeDropdownView(ddItems string) *guiWidget {
|
func makeDropdownView(ddItems string) *guiWidget {
|
||||||
newNode := addDropdown()
|
newNode := addDropdown()
|
||||||
tk := newNode.TK.(*guiWidget)
|
tk := newNode.TK.(*guiWidget)
|
||||||
|
@ -145,12 +156,12 @@ func (w *guiWidget) dropdownClicked(mouseW, mouseH int) string {
|
||||||
}
|
}
|
||||||
|
|
||||||
func dropdownUnclicked(mouseX, mouseH int) {
|
func dropdownUnclicked(mouseX, mouseH int) {
|
||||||
|
log.Log(GOCUI, "dropdownUnclicked() mouseup: got inside me.dropdown handler? wxh =", mouseX, mouseH)
|
||||||
if me.dropdownV == nil {
|
if me.dropdownV == nil {
|
||||||
log.Log(GOCUI, "mouseUp() dropdownV = nil", mouseX, mouseH)
|
log.Log(GOCUI, "mouseUp() dropdownV = nil", mouseX, mouseH)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
tk := me.dropdownV
|
tk := me.dropdownV
|
||||||
log.Log(GOCUI, "mouseUp() view msgMouseDown (check here for dropdown menu click) (w,h) =", mouseX, mouseH)
|
log.Log(GOCUI, fmt.Sprintf("dropdownUnclicked at apparently (w=%d h=%d)", mouseX, mouseH))
|
||||||
log.Log(GOCUI, "mouseUp() ddview is the thing that was clicked", mouseX, mouseH)
|
log.Log(GOCUI, "dropdownUnclicked() find out what the string is here", mouseX, mouseH, tk.gocuiSize.h1)
|
||||||
log.Log(GOCUI, "mouseUp() find out what the string is here", mouseX, mouseH, tk.gocuiSize.h1)
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,89 @@
|
||||||
|
// WIT.COM Inc. 2017-2025 GPL 3.0
|
||||||
|
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/awesome-gocui/gocui"
|
||||||
|
)
|
||||||
|
|
||||||
|
// tells 'gocui' what to call based on what key was pressed
|
||||||
|
func registerHandlers(g *gocui.Gui) {
|
||||||
|
g.SetKeybinding("", '?', gocui.ModNone, theHelp) // 'h' toggles on and off the help menu
|
||||||
|
g.SetKeybinding("", 'r', gocui.ModNone, widgetRefresh) // screen refresh
|
||||||
|
g.SetKeybinding("", 'w', gocui.ModNone, doWindow) // close all windows
|
||||||
|
g.SetKeybinding("", 'q', gocui.ModNone, doExit) // exit
|
||||||
|
g.SetKeybinding("", gocui.KeyCtrlC, gocui.ModNone, doExit) // exit
|
||||||
|
g.SetKeybinding("", gocui.KeyCtrlV, gocui.ModNone, doPanic) // forced panic
|
||||||
|
|
||||||
|
// debugging
|
||||||
|
g.SetKeybinding("", 'd', gocui.ModNone, theLetterD) // 'd' toggles on and off debugging buttons
|
||||||
|
g.SetKeybinding("", gocui.KeyCtrlD, gocui.ModNone, openDebuggger) // open the debugger
|
||||||
|
g.SetKeybinding("", 'L', gocui.ModNone, dumpWidgets) // list all widgets
|
||||||
|
g.SetKeybinding("", 'M', gocui.ModNone, dumpWidgetPlacement) // list all widgets with positions
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
func doExit(g *gocui.Gui, v *gocui.View) error {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func doPanic(g *gocui.Gui, v *gocui.View) error {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func dumpWidgets(g *gocui.Gui, v *gocui.View) error {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func dumpWidgetPlacement(g *gocui.Gui, v *gocui.View) error {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func openDebuggger(g *gocui.Gui, v *gocui.View) error {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// is run whenever anyone hits 'd' (in an open space)
|
||||||
|
func theLetterD(g *gocui.Gui, v *gocui.View) error {
|
||||||
|
// widgets that don't have physical existance in
|
||||||
|
// a display toolkit are hidden. In the case
|
||||||
|
// of gocui, they are set as not 'visible' and put offscreen
|
||||||
|
// or have the size set to zero
|
||||||
|
// (hopefully anyway) lots of things with the toolkit
|
||||||
|
// still don't work
|
||||||
|
|
||||||
|
fakeStartWidth = me.FakeW
|
||||||
|
fakeStartHeight = me.TabH + me.FramePadH
|
||||||
|
if showDebug {
|
||||||
|
showFake()
|
||||||
|
showDebug = false
|
||||||
|
} else {
|
||||||
|
hideFake()
|
||||||
|
showDebug = true
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func theHelp(g *gocui.Gui, v *gocui.View) error {
|
||||||
|
if showHelp {
|
||||||
|
helplayout()
|
||||||
|
showHelp = false
|
||||||
|
if me.dropdownV == nil {
|
||||||
|
me.dropdownV = makeDropdownView("addWidget() ddview")
|
||||||
|
}
|
||||||
|
me.dropdownV.Show()
|
||||||
|
} else {
|
||||||
|
me.baseGui.DeleteView("help")
|
||||||
|
showHelp = true
|
||||||
|
me.dropdownV.Hide()
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func widgetRefresh(g *gocui.Gui, v *gocui.View) error {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func doWindow(g *gocui.Gui, v *gocui.View) error {
|
||||||
|
return nil
|
||||||
|
}
|
9
gocui.go
9
gocui.go
|
@ -1,3 +1,6 @@
|
||||||
|
// Copyright 2017-2025 WIT.COM Inc. All rights reserved.
|
||||||
|
// Use of this source code is (now) governed by the GPL 3.0
|
||||||
|
|
||||||
// Copyright 2014 The gocui Authors. All rights reserved.
|
// Copyright 2014 The gocui Authors. All rights reserved.
|
||||||
// Use of this source code is governed by a BSD-style
|
// Use of this source code is governed by a BSD-style
|
||||||
// license that can be found in the LICENSE file.
|
// license that can be found in the LICENSE file.
|
||||||
|
@ -13,8 +16,6 @@ import (
|
||||||
"go.wit.com/log"
|
"go.wit.com/log"
|
||||||
)
|
)
|
||||||
|
|
||||||
var ecount int = 3
|
|
||||||
|
|
||||||
// Thanks to the gocui developers -- your package kicks ass
|
// Thanks to the gocui developers -- your package kicks ass
|
||||||
// This function is called on every event. It is a callback function from the gocui package
|
// This function is called on every event. It is a callback function from the gocui package
|
||||||
// which has an excellent implementation. While gocui handles things like text highlighting
|
// which has an excellent implementation. While gocui handles things like text highlighting
|
||||||
|
@ -22,7 +23,7 @@ var ecount int = 3
|
||||||
// complicated console handling, it sends events here in a clean way.
|
// complicated console handling, it sends events here in a clean way.
|
||||||
// This is equivalent to the linux command xev (apt install x11-utils)
|
// This is equivalent to the linux command xev (apt install x11-utils)
|
||||||
func gocuiEvent(g *gocui.Gui) error {
|
func gocuiEvent(g *gocui.Gui) error {
|
||||||
ecount += 1
|
me.ecount += 1
|
||||||
maxX, maxY := g.Size()
|
maxX, maxY := g.Size()
|
||||||
mx, my := g.MousePosition()
|
mx, my := g.MousePosition()
|
||||||
log.Verbose("handleEvent() START", maxX, maxY, mx, my, msgMouseDown)
|
log.Verbose("handleEvent() START", maxX, maxY, mx, my, msgMouseDown)
|
||||||
|
@ -36,7 +37,7 @@ func gocuiEvent(g *gocui.Gui) error {
|
||||||
// setOutput(me.logStdout)
|
// setOutput(me.logStdout)
|
||||||
// me.logStdout.Write("test out")
|
// me.logStdout.Write("test out")
|
||||||
w := me.logStdout.TK.(*guiWidget)
|
w := me.logStdout.TK.(*guiWidget)
|
||||||
msg := fmt.Sprintf("test out gocuiEvent() %d\n", ecount)
|
msg := fmt.Sprintf("test out gocuiEvent() %d\n", me.ecount)
|
||||||
w.Write([]byte(msg))
|
w.Write([]byte(msg))
|
||||||
// log.CaptureMode(w)
|
// log.CaptureMode(w)
|
||||||
log.Log(NOW, "logStdout test out")
|
log.Log(NOW, "logStdout test out")
|
||||||
|
|
4
help.go
4
help.go
|
@ -20,7 +20,9 @@ var helpText []string = []string{"KEYBINDINGS",
|
||||||
"s/h: show/hide all widgets",
|
"s/h: show/hide all widgets",
|
||||||
"L: list all widgets",
|
"L: list all widgets",
|
||||||
"M: list all widgets positions",
|
"M: list all widgets positions",
|
||||||
"\x1b[0;32m \x1b[0m",
|
|
||||||
|
"\x1b[0;32m \x1b[0m", // this was a test to see what might be
|
||||||
|
// possible with gocui. it doesn't seem to work for me
|
||||||
"q: quit()",
|
"q: quit()",
|
||||||
"p: panic()",
|
"p: panic()",
|
||||||
"o: show Stdout",
|
"o: show Stdout",
|
||||||
|
|
|
@ -63,19 +63,7 @@ func defaultKeybindings(g *gocui.Gui) error {
|
||||||
|
|
||||||
func addDebugKeys(g *gocui.Gui) {
|
func addDebugKeys(g *gocui.Gui) {
|
||||||
// show debugging buttons
|
// show debugging buttons
|
||||||
g.SetKeybinding("", 'd', gocui.ModNone,
|
g.SetKeybinding("", 'd', gocui.ModNone, theLetterD)
|
||||||
func(g *gocui.Gui, v *gocui.View) error {
|
|
||||||
fakeStartWidth = me.FakeW
|
|
||||||
fakeStartHeight = me.TabH + me.FramePadH
|
|
||||||
if showDebug {
|
|
||||||
showFake()
|
|
||||||
showDebug = false
|
|
||||||
} else {
|
|
||||||
hideFake()
|
|
||||||
showDebug = true
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
})
|
|
||||||
|
|
||||||
// display the help menu
|
// display the help menu
|
||||||
g.SetKeybinding("", '?', gocui.ModNone,
|
g.SetKeybinding("", '?', gocui.ModNone,
|
27
mouse.go
27
mouse.go
|
@ -2,6 +2,13 @@
|
||||||
// Use of this source code is governed by a BSD-style
|
// Use of this source code is governed by a BSD-style
|
||||||
// license that can be found in the LICENSE file.
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
|
// note by jcarr@wit.com in 2025: this is one of the coolest
|
||||||
|
// things ever what this does. I've tried to improve
|
||||||
|
// it while I've been working on making a gocui
|
||||||
|
// GO plugin so it can be generalized as a useful
|
||||||
|
// console interface. Well done everyone that has
|
||||||
|
// contributed to this gocui project !!!
|
||||||
|
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
@ -27,8 +34,13 @@ func mouseMove(g *gocui.Gui) {
|
||||||
|
|
||||||
func msgDown(g *gocui.Gui, v *gocui.View) error {
|
func msgDown(g *gocui.Gui, v *gocui.View) error {
|
||||||
initialMouseX, initialMouseY = g.MousePosition()
|
initialMouseX, initialMouseY = g.MousePosition()
|
||||||
|
|
||||||
|
// debugging output
|
||||||
log.Log(GOCUI, "msgDown() X,Y", initialMouseX, initialMouseY)
|
log.Log(GOCUI, "msgDown() X,Y", initialMouseX, initialMouseY)
|
||||||
if vx, vy, _, _, err := g.ViewPosition("msg"); err == nil {
|
|
||||||
|
//
|
||||||
|
vx, vy, _, _, err := g.ViewPosition("msg")
|
||||||
|
if err == nil {
|
||||||
xOffset = initialMouseX - vx
|
xOffset = initialMouseX - vx
|
||||||
yOffset = initialMouseY - vy
|
yOffset = initialMouseY - vy
|
||||||
msgMouseDown = true
|
msgMouseDown = true
|
||||||
|
@ -40,6 +52,7 @@ func mouseUp(g *gocui.Gui, v *gocui.View) error {
|
||||||
w, h := g.MousePosition()
|
w, h := g.MousePosition()
|
||||||
|
|
||||||
dropdownUnclicked(w, h)
|
dropdownUnclicked(w, h)
|
||||||
|
|
||||||
if msgMouseDown {
|
if msgMouseDown {
|
||||||
msgMouseDown = false
|
msgMouseDown = false
|
||||||
if movingMsg {
|
if movingMsg {
|
||||||
|
@ -55,16 +68,26 @@ func mouseUp(g *gocui.Gui, v *gocui.View) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// func isMouseInMsg
|
||||||
|
|
||||||
|
// this is where you have to figure out what
|
||||||
|
// widget was underneath so you can active
|
||||||
|
// the right response for the toolkit user's app
|
||||||
func mouseDown(g *gocui.Gui, v *gocui.View) error {
|
func mouseDown(g *gocui.Gui, v *gocui.View) error {
|
||||||
mx, my := g.MousePosition()
|
mx, my := g.MousePosition()
|
||||||
if vx0, vy0, vx1, vy1, err := g.ViewPosition("msg"); err == nil {
|
|
||||||
|
vx0, vy0, vx1, vy1, err := g.ViewPosition("msg")
|
||||||
|
if err == nil {
|
||||||
if mx >= vx0 && mx <= vx1 && my >= vy0 && my <= vy1 {
|
if mx >= vx0 && mx <= vx1 && my >= vy0 && my <= vy1 {
|
||||||
return msgDown(g, v)
|
return msgDown(g, v)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
globalMouseDown = true
|
globalMouseDown = true
|
||||||
|
|
||||||
maxX, _ := g.Size()
|
maxX, _ := g.Size()
|
||||||
|
|
||||||
findUnderMouse()
|
findUnderMouse()
|
||||||
|
|
||||||
msg := fmt.Sprintf("mouseDown() Mouse really down at: %d,%d", mx, my)
|
msg := fmt.Sprintf("mouseDown() Mouse really down at: %d,%d", mx, my)
|
||||||
// dropdownClicked(mx, my)
|
// dropdownClicked(mx, my)
|
||||||
x := mx - len(msg)/2
|
x := mx - len(msg)/2
|
||||||
|
|
|
@ -102,6 +102,10 @@ type config struct {
|
||||||
|
|
||||||
// used to attempt to write to the stdout window
|
// used to attempt to write to the stdout window
|
||||||
fakefile *FakeFile
|
fakefile *FakeFile
|
||||||
|
|
||||||
|
// just a counter for curiosity.
|
||||||
|
// counts how many mouse and keyboard events have occurred
|
||||||
|
ecount int
|
||||||
}
|
}
|
||||||
|
|
||||||
// deprecate these
|
// deprecate these
|
||||||
|
|
Loading…
Reference in New Issue