lots of work to clean up my old code
This commit is contained in:
parent
b7cd6d07fc
commit
bac14a675b
|
@ -155,8 +155,8 @@ func (w *guiWidget) dropdownClicked(mouseW, mouseH int) string {
|
|||
return ""
|
||||
}
|
||||
|
||||
var dtoggle bool // temporarily tracking show & hide
|
||||
var doffset int = 5 // how many spaces over the dropdown menu should be from the mouse
|
||||
var dtoggle bool = false // temporarily tracking show & hide
|
||||
var doffset int = 5 // how many spaces over the dropdown menu should be from the mouse
|
||||
|
||||
func dropdownUnclicked(w, h int) {
|
||||
var d *guiWidget
|
||||
|
|
106
eventBindings.go
106
eventBindings.go
|
@ -5,45 +5,114 @@ package main
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"syscall"
|
||||
|
||||
"github.com/awesome-gocui/gocui"
|
||||
log "go.wit.com/log"
|
||||
"go.wit.com/log"
|
||||
)
|
||||
|
||||
// tells 'gocui' what to call based on what key was pressed
|
||||
// THIS IS A STANDARD.
|
||||
|
||||
// register how the 'gocui' will work as a GO toolkit plugin
|
||||
// all applications will use these keys. they are universal.
|
||||
|
||||
// tells 'gocui' where to send events
|
||||
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
|
||||
keyForced, modForced := gocui.MustParse("ctrl+z") // setup ctrl+z
|
||||
|
||||
// mouse handlers
|
||||
g.SetKeybinding("", gocui.MouseLeft, gocui.ModNone, mouseDown) // normal left mouse down
|
||||
g.SetKeybinding("", gocui.MouseLeft, gocui.ModMouseCtrl, ctrlDown) // mouse with the ctrl key held down
|
||||
g.SetKeybinding("", gocui.MouseRelease, gocui.ModNone, mouseUp) // mouse button release
|
||||
|
||||
// Ctrl key handlers
|
||||
g.SetKeybinding("", gocui.KeyCtrlC, gocui.ModNone, doExit) // CTRL-C : exits the application
|
||||
g.SetKeybinding("", gocui.KeyCtrlV, gocui.ModNone, doPanic) // CTRL-V : force a panic()
|
||||
g.SetKeybinding("", gocui.KeyCtrlD, gocui.ModNone, openDebuggger) // CTRL-D : open the (D)ebugger
|
||||
g.SetKeybinding("", keyForced, modForced, handle_ctrl_z) // CTRL-Z :cleverly let's you background gocui (breaks cursor mouse on return)
|
||||
|
||||
// regular keys
|
||||
g.SetKeybinding("", '?', gocui.ModNone, theHelp) // '?' toggles on and off the help menu
|
||||
g.SetKeybinding("", 'w', gocui.ModNone, doWindow) // 'w' close all windows
|
||||
g.SetKeybinding("", 'r', gocui.ModNone, widgetRefresh) // 'r' screen refresh
|
||||
g.SetKeybinding("", 'q', gocui.ModNone, doExit) // 'q' exit
|
||||
|
||||
// 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
|
||||
g.SetKeybinding("", 'f', gocui.ModNone, theFind) // 'f' shows what is under your mouse
|
||||
g.SetKeybinding("", 'S', gocui.ModNone, setSuperMouse) // 'S' Super Mouse mode!
|
||||
g.SetKeybinding("", 'h', gocui.ModNone, theHide) // 'h' hide all widgets
|
||||
g.SetKeybinding("", 'M', gocui.ModNone, dumpWidgetPlacement) // 'M' list all widgets with positions
|
||||
g.SetKeybinding("", 'L', gocui.ModNone, dumpWidgets) // 'L' list all widgets in tree view
|
||||
g.SetKeybinding("", 'd', gocui.ModNone, theLetterD) // 'd' toggles on and off debugging buttons
|
||||
g.SetKeybinding("", 'q', gocui.ModNone, quit) // 'q' only exits gocui. plugin stays alive (?)
|
||||
}
|
||||
|
||||
// flips on 'super mouse' mode
|
||||
// while this is turned on, it will print out every widget found under the mouse
|
||||
func setSuperMouse(g *gocui.Gui, v *gocui.View) error {
|
||||
if me.supermouse {
|
||||
log.Log(GOCUI, "supermouse off")
|
||||
me.supermouse = false
|
||||
} else {
|
||||
me.supermouse = true
|
||||
log.Log(GOCUI, "supermouse on")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func theHide(g *gocui.Gui, v *gocui.View) error {
|
||||
var w *guiWidget
|
||||
w = me.treeRoot.TK.(*guiWidget)
|
||||
w.hideWidgets()
|
||||
return nil
|
||||
}
|
||||
|
||||
func theShow(g *gocui.Gui, v *gocui.View) error {
|
||||
var w *guiWidget
|
||||
w = me.treeRoot.TK.(*guiWidget)
|
||||
w.showWidgets()
|
||||
return nil
|
||||
}
|
||||
|
||||
func doExit(g *gocui.Gui, v *gocui.View) error {
|
||||
standardExit()
|
||||
return nil
|
||||
}
|
||||
|
||||
func doPanic(g *gocui.Gui, v *gocui.View) error {
|
||||
log.Log(GOCUI, "do panic() here")
|
||||
standardClose()
|
||||
panic("forced panic in gocui")
|
||||
return nil
|
||||
}
|
||||
|
||||
func dumpWidgets(g *gocui.Gui, v *gocui.View) error {
|
||||
me.treeRoot.ListWidgets()
|
||||
|
||||
tk := me.logStdout.TK.(*guiWidget)
|
||||
// msg := fmt.Sprintf("test out kb %d\n", ecount)
|
||||
// tk.Write([]byte(msg))
|
||||
if tk == nil {
|
||||
log.Log(ERROR, "tk = nil")
|
||||
}
|
||||
if tk.v == nil {
|
||||
log.Log(ERROR, "tk.v = nil")
|
||||
} else {
|
||||
log.Log(ERROR, "setting log.CaptureMode(tk.v)")
|
||||
log.Log(ERROR, "setting log.CaptureMode(tk.v)")
|
||||
log.CaptureMode(tk)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func dumpWidgetPlacement(g *gocui.Gui, v *gocui.View) error {
|
||||
w := me.treeRoot.TK.(*guiWidget)
|
||||
w.dumpTree("MM")
|
||||
return nil
|
||||
}
|
||||
|
||||
func openDebuggger(g *gocui.Gui, v *gocui.View) error {
|
||||
me.myTree.SendEnableDebugger()
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -93,9 +162,22 @@ func theHelp(g *gocui.Gui, v *gocui.View) error {
|
|||
}
|
||||
|
||||
func widgetRefresh(g *gocui.Gui, v *gocui.View) error {
|
||||
log.Log(GOCUI, "todo: refresh windows here")
|
||||
return nil
|
||||
}
|
||||
|
||||
func doWindow(g *gocui.Gui, v *gocui.View) error {
|
||||
log.Log(GOCUI, "todo: close all windows here")
|
||||
return nil
|
||||
}
|
||||
|
||||
// todo: find and give credit to the person that I found this patch in their forked repo
|
||||
// handle ctrl+z
|
||||
func handle_ctrl_z(g *gocui.Gui, v *gocui.View) error {
|
||||
gocui.Suspend()
|
||||
log.Info("got ctrl+z")
|
||||
syscall.Kill(syscall.Getpid(), syscall.SIGSTOP)
|
||||
log.Info("got ctrl+z syscall() done")
|
||||
gocui.Resume()
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -51,6 +51,7 @@ func gocuiEvent(g *gocui.Gui) error {
|
|||
}
|
||||
|
||||
func dragOutputWindow() {
|
||||
log.Log(GOCUI, "todo: make dragOutputWindow")
|
||||
}
|
||||
|
||||
// turns off the frame on the global window
|
||||
|
@ -64,6 +65,8 @@ func setFrame(b bool) {
|
|||
v.Frame = b
|
||||
}
|
||||
|
||||
// a test. exits gocui, but the application still runs
|
||||
// maybe can switch toolkits?
|
||||
func quit(g *gocui.Gui, v *gocui.View) error {
|
||||
return gocui.ErrQuit
|
||||
}
|
||||
|
|
|
@ -29,6 +29,16 @@ import (
|
|||
// this is run every time the user moves the mouse over the terminal window
|
||||
func mouseMove(g *gocui.Gui) {
|
||||
mx, my := g.MousePosition()
|
||||
|
||||
w := mx
|
||||
h := my
|
||||
|
||||
if me.supermouse {
|
||||
for _, tk := range findByXY(w, h) {
|
||||
log.Log(GOCUI, fmt.Sprintf("findByXY() mouseMove() %s wId=%d cuiName=%s at (%d,%d)", tk.WidgetType, tk.node.WidgetId, tk.cuiName, w, h))
|
||||
}
|
||||
}
|
||||
|
||||
for _, view := range g.Views() {
|
||||
view.Highlight = false
|
||||
}
|
||||
|
|
21
help.go
21
help.go
|
@ -12,17 +12,22 @@ import (
|
|||
"github.com/awesome-gocui/gocui"
|
||||
)
|
||||
|
||||
var helpText []string = []string{"KEYBINDINGS",
|
||||
"",
|
||||
"?: toggle zhelp",
|
||||
"d: toggle debugging",
|
||||
"r: redraw widgets",
|
||||
"s/h: show/hide all widgets",
|
||||
"L: list all widgets",
|
||||
"M: list all widgets positions",
|
||||
/*
|
||||
This in helpText doesn't print
|
||||
|
||||
"\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
|
||||
*/
|
||||
|
||||
var helpText []string = []string{"KEYBINDINGS",
|
||||
"",
|
||||
"?: toggle zhelp",
|
||||
"S: super mouse",
|
||||
"M: list all widgets positions",
|
||||
"L: list all widgets in tree form",
|
||||
"d: toggle debugging",
|
||||
"s/h: show/hide all widgets",
|
||||
|
||||
"q: quit()",
|
||||
"p: panic()",
|
||||
"o: show Stdout",
|
||||
|
|
15
init.go
15
init.go
|
@ -165,11 +165,16 @@ func gocuiMain() {
|
|||
// This is equivalent to xev or similar to cat /dev/input on linux
|
||||
g.SetManagerFunc(gocuiEvent)
|
||||
|
||||
if err := defaultKeybindings(g); err != nil {
|
||||
// normally panic here
|
||||
log.Log(NOW, "defaultKeybindings(g) panic err =", err)
|
||||
panic("gocuiTKdefaultkeybindings OOPS")
|
||||
}
|
||||
// register how the 'gocui' will work as a GO toolkit plugin
|
||||
// all applications will use these keys. they are universal.
|
||||
registerHandlers(g)
|
||||
/*
|
||||
if err := defaultKeybindings(g); err != nil {
|
||||
// normally panic here
|
||||
log.Log(NOW, "defaultKeybindings(g) panic err =", err)
|
||||
panic("gocuiTKdefaultkeybindings OOPS")
|
||||
}
|
||||
*/
|
||||
|
||||
if err := g.MainLoop(); err != nil && !errors.Is(err, gocui.ErrQuit) {
|
||||
log.Log(NOW, "g.MainLoop() panic err =", err)
|
||||
|
|
13
junk1.go
13
junk1.go
|
@ -6,24 +6,13 @@ package main
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"syscall"
|
||||
|
||||
"github.com/awesome-gocui/gocui"
|
||||
|
||||
"go.wit.com/log"
|
||||
)
|
||||
|
||||
// handle ctrl+z
|
||||
func handle_ctrl_z(g *gocui.Gui, v *gocui.View) error {
|
||||
gocui.Suspend()
|
||||
log.Info("got ctrl+z")
|
||||
syscall.Kill(syscall.Getpid(), syscall.SIGSTOP)
|
||||
log.Info("got ctrl+z syscall() done")
|
||||
gocui.Resume()
|
||||
return nil
|
||||
}
|
||||
|
||||
func defaultKeybindings(g *gocui.Gui) error {
|
||||
func OLDdefaultKeybindings(g *gocui.Gui) error {
|
||||
if err := g.SetKeybinding("", gocui.KeyCtrlC, gocui.ModNone, quit); err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
18
structs.go
18
structs.go
|
@ -94,18 +94,14 @@ type config struct {
|
|||
stretchy bool // expand things like buttons to the maximum size
|
||||
margin bool // add space around the frames of windows
|
||||
|
||||
// writeMutex protects locks the write process
|
||||
writeMutex sync.Mutex
|
||||
writeMutex sync.Mutex // TODO: writeMutex protects locks the write process
|
||||
fakefile *FakeFile // JUNK? used to attempt to write to the stdout window
|
||||
dtoggle bool // is a dropdown or combobox currently active?
|
||||
|
||||
// used for listWidgets() debugging
|
||||
depth int
|
||||
|
||||
// used to attempt to write to the stdout window
|
||||
fakefile *FakeFile
|
||||
|
||||
// just a counter for curiosity.
|
||||
// counts how many mouse and keyboard events have occurred
|
||||
ecount int
|
||||
// debugging things
|
||||
ecount int // counts how many mouse and keyboard events have occurred
|
||||
supermouse bool // prints out every widget found while you move the mouse around
|
||||
depth int // used for listWidgets() debugging
|
||||
}
|
||||
|
||||
// deprecate these
|
||||
|
|
Loading…
Reference in New Issue