nicer help menu & stdout behavior

This commit is contained in:
Jeff Carr 2025-02-06 02:15:21 -06:00
parent 31c130045d
commit 3faacd6c43
4 changed files with 33 additions and 32 deletions

View File

@ -32,25 +32,23 @@ func registerHandlers(g *gocui.Gui) {
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("", 'H', gocui.ModNone, theHelp) // '?' toggles on and off the help menu
g.SetKeybinding("", 'O', gocui.ModNone, theStdout) // 'o' toggle the STDOUT window
g.SetKeybinding("", 'q', gocui.ModNone, doExit) // 'q' exit
// debugging
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("", '2', gocui.ModNone, theNotsure) // '2' use this to test new ideas
g.SetKeybinding("", 'S', gocui.ModNone, theSuperMouse) // 'S' Super Mouse mode!
g.SetKeybinding("", 'M', gocui.ModNone, printWidgetPlacements) // 'M' list all widgets with positions
g.SetKeybinding("", 'L', gocui.ModNone, printWidgetTree) // 'L' list all widgets in tree view
g.SetKeybinding("", 'f', gocui.ModNone, theFind) // 'f' shows what is under your mouse
g.SetKeybinding("", 'd', gocui.ModNone, theLetterD) // 'd' toggles on and off debugging buttons
g.SetKeybinding("", '2', gocui.ModNone, theNotsure) // '2' for testing new ideas
g.SetKeybinding("", 'q', gocui.ModNone, quit) // 'q' only exits gocui. plugin stays alive (?)
}
// flips on 'super mouse' mode
// flips on 'super mouse' mode // this was awesome for debugging gocui. never remove this code.
// while this is turned on, it will print out every widget found under the mouse
func setSuperMouse(g *gocui.Gui, v *gocui.View) error {
func theSuperMouse(g *gocui.Gui, v *gocui.View) error {
if me.supermouse {
log.Log(GOCUI, "supermouse off")
me.supermouse = false
@ -93,18 +91,22 @@ func addDropdown() *tree.Node {
return addDropdownNew(-222)
}
// use this to test code ideas
// use this to test code ideas // put whatever you want here and hit '2' to activate it
func theNotsure(g *gocui.Gui, v *gocui.View) error {
log.Info("got keypress 2. now what?")
// w, h := g.MousePosition()
me.newWindowTrigger <- true
// me.newWindowTrigger <- true
return nil
}
func theHide(g *gocui.Gui, v *gocui.View) error {
var w *guiWidget
w = me.treeRoot.TK.(*guiWidget)
w.hideWidgets()
func theStdout(g *gocui.Gui, v *gocui.View) error {
if me.outputOnTop {
me.outputOnTop = false
me.baseGui.SetViewOnBottom("msg")
} else {
me.outputOnTop = true
me.baseGui.SetViewOnTop("msg")
}
return nil
}
@ -173,16 +175,6 @@ func theHelp(g *gocui.Gui, v *gocui.View) error {
return nil
}
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 {

View File

@ -98,7 +98,7 @@ func (tk *guiWidget) moveNew() {
w, h := me.baseGui.MousePosition()
if tk.node.WidgetType == widget.Window {
tk.redrawWindow(w-tk.dragW, h-tk.dragH) // TODO: fix these hard coded things with offsets
helpTop() // sets the help window as the top view
setThingsOnTop() // sets help, Stdout, etc on the top after windows have been redrawn
return
}
if tk.node.WidgetType == widget.Flag {
@ -141,7 +141,7 @@ func (tk *guiWidget) moveNew() {
*/
}
// always place the help menu on top
helpTop() // sets the help window as the top view
setThingsOnTop() // sets help, Stdout, etc on the top after windows have been redrawn
}
func createStdout(g *gocui.Gui) bool {

14
help.go
View File

@ -25,7 +25,8 @@ import (
var helpText []string = []string{"KEYBINDINGS",
"",
"?: toggle help",
"H: toggle (H)elp",
"O: toggle (O)output (os.STDOUT)",
"S: super mouse",
"M: list all widgets positions",
"L: list all widgets in tree form",
@ -34,7 +35,6 @@ var helpText []string = []string{"KEYBINDINGS",
"q: quit()",
"p: panic()",
"o: show Stdout",
"l: log to /tmp/witgui.log",
"Ctrl-D: Toggle Debugging",
"Ctrl-V: Toggle Verbose Debugging",
@ -93,10 +93,18 @@ func showHelp() error {
return nil
}
func helpTop() {
// in the very end of redrawing things, this will place the help and stdout on the top or botton
// depending on the state the user has chosen
func setThingsOnTop() {
if me.showHelp { // terrible variable name. FIXME
// log.Info("help is hidden")
return
}
me.baseGui.SetViewOnTop("help")
if me.outputOnTop {
me.baseGui.SetViewOnTop("msg")
} else {
me.baseGui.SetViewOnBottom("msg")
}
}

View File

@ -39,6 +39,8 @@ type config struct {
startOutputW int // ?
startOutputH int // ?
helpLabel *gocui.View // ?
showHelp bool // toggle boolean for the help menu (deprecate?)
outputOnTop bool // is the STDOUT window on top?
// dropdownV *guiWidget // this is a floating widget that we show whenever the user clicks on a
dropdownW *guiWidget // grab the dropdown choices from this widget
FramePadW int `default:"1" dense:"0"` // When the widget has a frame, like a button, it adds 2 lines runes on each side
@ -65,7 +67,6 @@ type config struct {
margin bool // add space around the frames of windows
writeMutex sync.Mutex // writeMutex protects writes to *guiWidget (it's global right now maybe)
dtoggle bool // is a dropdown or combobox currently active?
showHelp bool // toggle boolean for the help menu (deprecate?)
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