Compare commits

...

8 Commits

Author SHA1 Message Date
Jeff Carr 86aa5fb001 reverse in STDOUT is no longer the default 2025-09-03 01:56:01 -05:00
Jeff Carr 262426fb44 make the help menu appear when libnotify is clicked 2025-09-03 01:23:22 -05:00
Jeff Carr ec0807ce2b minor 2025-08-16 21:49:54 -05:00
Jeff Carr ce1d9457f9 syntax change 2025-06-04 06:34:06 -05:00
Jeff Carr 664ce4dfae rm old code 2025-04-30 14:41:27 -05:00
Jeff Carr 7b6af30194 text edit box kinda works sometimes 2025-04-24 19:28:33 -05:00
Jeff Carr e0c55e73d2 more standard SetView() 2025-04-22 20:50:14 -05:00
Jeff Carr 4efbfa7a1d fixing textboxes 2025-04-22 18:49:16 -05:00
16 changed files with 166 additions and 137 deletions

1
.gitignore vendored
View File

@ -5,3 +5,4 @@
go.mod
go.sum
gocui
resources/*.so

View File

@ -25,7 +25,7 @@ custom:
clean:
rm -f gocui *.so go.*
rm -f *.pb.go *.patch
go-mod-clean --purge
go-mod-clean purge
# Test the README.md & doc.go file
# this runs pkgsite, the binary that does dev.go.dev

View File

@ -58,6 +58,7 @@ func registerHandlers(g *gocui.Gui) {
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("", 'r', gocui.ModNone, reverseStdout) // 'r' turns scrolling of STDOUT upside down
g.SetKeybinding("", 'q', gocui.ModNone, quit) // 'q' only exits gocui. plugin stays alive (?)
}
@ -103,7 +104,9 @@ func theDarkness(g *gocui.Gui, v *gocui.View) error {
log.Info("you have seen the light")
} else {
me.dark = true
log.Info("you have entered into darkness")
log.Info("you have entered into darkness (you may need to trigger SIGWINCH)")
log.Info("or maybe open a new window. notsure. This obviously isn't finished.")
log.Info("submit patches to this and you will definitely get free cloud credits at WIT")
}
return nil
}
@ -138,11 +141,13 @@ func doEsc(g *gocui.Gui, v *gocui.View) error {
me.dropdown.tk.Hide()
me.dropdown.active = false
log.Info("escaped from dropdown")
me.baseGui.SetCurrentView(me.notify.clock.tk.cuiName)
}
if me.textbox.active {
me.textbox.tk.Hide()
me.textbox.active = false
log.Info("escaped from textbox")
me.baseGui.SetCurrentView(me.notify.clock.tk.cuiName)
}
return nil
}
@ -180,6 +185,19 @@ func theFind(g *gocui.Gui, v *gocui.View) error {
return nil
}
func reverseStdout(g *gocui.Gui, v *gocui.View) error {
if me.stdout.reverse {
me.stdout.reverse = false
log.Info("stdout scrolling normal")
} else {
me.stdout.reverse = true
log.Info("stdout scrolling is reversed. this is sometimes useful when you")
log.Info("only need to see a few most recent lines and have the STDOUT window")
log.Info("take up minimal realestate at the bottom of your window")
}
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

View File

@ -77,12 +77,20 @@ func stdoutHome(g *gocui.Gui, v *gocui.View) error {
}
func stdoutArrowUp(g *gocui.Gui, v *gocui.View) error {
if me.stdout.reverse {
stdoutWheelsDown()
} else {
stdoutWheelsUp()
}
return nil
}
func stdoutArrowDown(g *gocui.Gui, v *gocui.View) error {
if me.stdout.reverse {
stdoutWheelsUp()
} else {
stdoutWheelsDown()
}
return nil
}

View File

@ -5,6 +5,7 @@ package main
import (
"errors"
"fmt"
"github.com/awesome-gocui/gocui"
"go.wit.com/log"
@ -39,6 +40,36 @@ func quit(g *gocui.Gui, v *gocui.View) error {
return gocui.ErrQuit
}
func (tk *guiWidget) SetView() error {
if me.baseGui == nil {
return fmt.Errorf("me.baseGui == nil")
}
r := new(rectType)
r.w0 = tk.gocuiSize.w0
r.h0 = tk.gocuiSize.h0
r.w1 = tk.gocuiSize.w1
r.h1 = tk.gocuiSize.h1
return tk.SetViewRect(r)
}
func (tk *guiWidget) SetViewRect(r *rectType) error {
if me.baseGui == nil {
return fmt.Errorf("me.baseGui == nil")
}
var err error
tk.v, err = me.baseGui.SetView(tk.cuiName, r.w0, r.h0, r.w1, r.h1, 0)
if err != nil {
if !errors.Is(err, gocui.ErrUnknownView) {
log.Log(ERROR, "SetView() global failed on name =", tk.cuiName)
return err
}
}
return nil
}
func SetView(name string, x0, y0, x1, y1 int, overlaps byte) *gocui.View {
if me.baseGui == nil {
log.Log(ERROR, "SetView() ERROR: me.baseGui == nil")

View File

@ -27,7 +27,7 @@ func doMouseClick(w int, h int) {
// can't drag or do anything when dropdown or textbox are visible
for _, tk := range findByXY(w, h) {
if tk.WidgetId() == me.dropdown.wId {
log.Info("got dropdwon click", w, h, tk.cuiName)
log.Info("got dropdown click", w, h, tk.cuiName)
tk.dropdownClicked(w, h)
return
}
@ -107,6 +107,7 @@ func doMouseClick(w int, h int) {
tk.showDropdown()
return
case widget.Textbox:
log.Log(WARN, "TODO: textbox click")
tk.prepTextbox()
return
case widget.Label:

View File

@ -111,15 +111,7 @@ func (tk *guiWidget) moveNew() {
tk.makeWindowActive()
return
}
/*
if tk.WidgetType() == widget.Flag {
me.baseGui.SetView(tk.cuiName, w-3, h-3, w+20, h+20, 0)
// tk.verifyRect()
s := fmt.Sprintf("move(%dx%d) %s ###", w, h, tk.cuiName)
tk.dumpWidget(s)
return
}
*/
if tk.WidgetType() == widget.Stdout {
if me.mouse.resize {
newW := w - me.stdout.lastW

13
find.go
View File

@ -129,13 +129,6 @@ func findWindowUnderMouse() *guiWidget {
}
}
/*
// print out the window list
for _, tk := range me.allwin {
log.Info("findWindowUnderMouse() print:", tk.labelN, tk.window.active, tk.window.order)
}
*/
// now check if the active window is below the mouse
for _, tk := range me.allwin {
if tk.window.active {
@ -152,12 +145,6 @@ func findWindowUnderMouse() *guiWidget {
return a.window.order - b.window.order
})
/*
// print out the window list
for _, tk := range me.allwin {
log.Info("findWindowUnderMouse() print:", tk.labelN, tk.window.active, tk.window.order)
}
*/
for _, win := range me.allwin {
if win.full.inRect(w, h) {
// log.Info(fmt.Sprintf("findWindowUnderMouse() found %s window (%dx%d)", win.cuiName, w, h))

20
help.go
View File

@ -25,16 +25,20 @@ import (
var helpText []string = []string{"Help Menu",
"",
"Tab: toggle through windows",
"O: toggle STDOUT",
"H: toggle this gocui menu",
"L: toggle light/dark mode",
"CTRL-c: quit()",
"Tab toggle through windows",
"'O' toggle STDOUT",
"'H' toggle this gocui menu",
"'D' toggle light/dark mode",
"CTRL-z background to shell",
"CTRL-c quit()",
"",
"Debugging:",
"S: Supermouse mode",
"M: list all widget positions",
"L: list all widgets in tree",
"'S' Supermouse mode",
"'M' list all widget positions",
"'L' list all widgets in tree",
"<Pgup> scroll up the STDOUT window",
"<Pgdn> scroll down the STDOUT window",
"'r' reverse STDOUT scrolling",
}
func hideHelp() {

View File

@ -108,7 +108,6 @@ func toolkitInit() {
if me.textbox.tk == nil {
log.Log(INFO, "gocui toolkitInit() initTextbox me.ok =", me.ok)
initTextbox()
me.textbox.tk.prepTextbox()
}
// TEST TEXTBOX END
}
@ -457,7 +456,6 @@ func newWindowTrigger() {
}
if me.textbox.tk == nil {
initTextbox()
me.textbox.tk.prepTextbox()
}
tk.makeWindowActive()
me.myTree.Unlock()

View File

@ -150,6 +150,17 @@ func setNotifyIconText(s string) {
me.notify.icon.tk.setColorNotifyIcon()
me.baseGui.SetViewOnTop(me.notify.icon.tk.v.Name())
log.Info("setNotifyIconText() updated menu to:", me.notify.icon.tk.labelN)
// print out the window list // TODO: put this in libnotify
for _, tk := range me.allwin {
log.Info("known window Window", tk.labelN, tk.window.active, tk.window.order)
}
if s == "[X]" {
log.Warn("should turn on help window here")
showHelp()
} else {
log.Warn("should turn off help window here")
hideHelp()
}
}
// in the very end of redrawing things, this will place the help and stdout on the top or botton
@ -207,15 +218,14 @@ func hardDrawUnderMouse(tk *guiWidget, name string) {
tk.Hide()
}
w, h := me.baseGui.MousePosition()
a := w
b := h
c := w + 8
d := h + 4
var err error
tk.v, err = me.baseGui.SetView(tk.cuiName, a, b, c, d, 0)
if err == nil {
log.Info("hardDrawUnderMouse() err ok widget", tk.cuiName)
tk.dumpWidget("hard draw err")
r := new(rectType)
r.w0 = w
r.h0 = h
r.w1 = w + 8
r.h1 = h + 4
if err := tk.SetViewRect(r); err != nil {
log.Info("hardDrawUnderMouse() err", tk.cuiName, err)
tk.dumpWidget("hardDrawERR")
}
tk.v.Frame = false
tk.v.Clear()
@ -226,20 +236,14 @@ func hardDrawAtgocuiSize(tk *guiWidget) {
if tk.v != nil {
tk.Hide()
}
a := tk.gocuiSize.w0
b := tk.gocuiSize.h0
c := tk.gocuiSize.w1
d := tk.gocuiSize.h1
var err error
tk.v, err = me.baseGui.SetView(tk.cuiName, a, b, c, d, 0)
if err == nil {
if err := tk.SetView(); err != nil {
log.Info("hardDrawAtgocuiSize() err ok widget", tk.cuiName)
tk.dumpWidget("hard draw err")
tk.dumpWidget("hardDrawERR")
}
tk.v.Frame = false
tk.v.Clear()
tk.v.WriteString(tk.labelN)
log.Verbose("hardDrawAtgocuiSize() err ok widget", tk.cuiName, a, b, c, d, tk.v.Name())
// log.Verbose("hardDrawAtgocuiSize() err ok widget", tk.cuiName, a, b, c, d, tk.v.Name())
}
func sigWinchIcon() {
@ -252,20 +256,15 @@ func sigWinchIcon() {
func sigWinchBG() {
tk := me.BG.tk
w, h := me.baseGui.Size()
a := -1
b := -1
c := w + 1
d := h + 1
var err error
tk.v, err = me.baseGui.SetView(tk.cuiName, a, b, c, d, 0)
if err == nil {
if tk.v == nil {
tk.dumpWidget("drawView() err")
log.Log(ERROR, "drawView() internal plugin error err = nil")
tk.gocuiSize.w0 = -1
tk.gocuiSize.h0 = -1
tk.gocuiSize.w1 = w + 1
tk.gocuiSize.h1 = h + 1
if err := tk.SetView(); err != nil {
tk.dumpWidget("sigWinchBGerr()")
log.Log(ERROR, "sigWinchBG()", err)
}
return
}
log.Log(INFO, "background resized to", a, b, c, d)
log.Log(INFO, "background resized to", tk.gocuiSize)
}
// find the "BG" widget and set it to the background on the very very bottom
@ -288,5 +287,9 @@ func setBottomBG() {
tk.v.Clear()
me.baseGui.SetViewOnBottom(tk.cuiName)
w, h := me.baseGui.Size()
me.baseGui.SetView(tk.cuiName, -1, -1, w+1, h+1, 0)
tk.gocuiSize.w0 = -1
tk.gocuiSize.h0 = -1
tk.gocuiSize.w1 = w + 1
tk.gocuiSize.h1 = h + 1
tk.SetView()
}

View File

@ -162,10 +162,10 @@ func (tk *guiWidget) GetText() string {
return ""
}
// hack. use "textbox widget" to "disable" user events
func hideDisable() {
if me.textbox.tk == nil {
initTextbox()
me.textbox.tk.prepTextbox()
}
me.textbox.tk.Hide()
@ -177,6 +177,7 @@ func hideDisable() {
// me.baseGui.DeleteView(me.textbox.tk.v.Name())
}
// hack. use "textbox widget" to "disable" user events
func showDisable() {
if me.textbox.tk == nil {
initTextbox()
@ -200,7 +201,7 @@ func showDisable() {
me.textbox.tk.v.Editable = true
me.textbox.tk.v.Wrap = true
me.baseGui.SetView(me.textbox.tk.cuiName, r.w0, r.h0, r.w1, r.h1, 0)
me.textbox.tk.SetViewRect(r)
me.baseGui.SetCurrentView(me.textbox.tk.v.Name())
// bind the enter key to a function so we can close the textbox

View File

@ -4,7 +4,6 @@
package main
import (
"errors"
"fmt"
"slices"
"strings"
@ -46,6 +45,7 @@ func coreStdout() {
me.stdout.tk = initWidget(n)
tk := me.stdout.tk
tk.cuiName = "msg"
tk.gocuiSize.w0 = me.stdout.lastW
tk.gocuiSize.h0 = me.stdout.lastH
tk.gocuiSize.w1 = tk.gocuiSize.w0 + me.stdout.w
@ -64,6 +64,9 @@ func makeOutputWidget(g *gocui.Gui, stringFromMouseClick string) *gocui.View {
return nil
}
me.stdout.tk.cuiName = "msg"
me.stdout.tk.SetView()
v, err := g.View("msg")
if v == nil {
// log.Log(NOW, "makeoutputwindow() this is supposed to happen. v == nil", err)
@ -72,27 +75,7 @@ func makeOutputWidget(g *gocui.Gui, stringFromMouseClick string) *gocui.View {
return v
}
rect := me.stdout.tk.gocuiSize
v, err = g.SetView("msg", rect.w0, rect.h0, rect.w1, rect.h1, 0)
if errors.Is(err, gocui.ErrUnknownView) {
// log.Log(NOW, "makeoutputwindow() this is supposed to happen?", err)
}
if err != nil {
if v == nil {
log.Log(NOW, "makeoutputwindow() BAD: v == nil && err =", err)
}
log.Log(NOW, "makeoutputwindow() create output window failed", err)
return nil
}
if v == nil {
log.Log(NOW, "makeoutputwindow() msg == nil. WTF now? err =", err)
return nil
} else {
me.stdout.tk.v = v
}
v = me.stdout.tk.v
v.Clear()
v.SelBgColor = gocui.ColorCyan
@ -101,16 +84,8 @@ func makeOutputWidget(g *gocui.Gui, stringFromMouseClick string) *gocui.View {
// g.SetViewOnBottom("msg")
// setBottomBG()
me.stdout.tk.v = v
me.stdout.tk.DrawAt(me.stdout.lastW, me.stdout.lastH)
relocateStdoutOffscreen()
/*
if me.stdout.outputOffscreen {
me.stdout.tk.relocateStdout(me.stdout.lastW, me.stdout.lastH)
} else {
relocateStdoutOffscreen()
}
*/
return v
}
@ -128,6 +103,22 @@ func relocateStdoutOffscreen() {
}
func (tk *guiWidget) relocateStdout(w int, h int) {
if me.stdout.w < 8 {
me.stdout.w = 8
}
if me.stdout.h < 4 {
me.stdout.h = 4
}
if w+me.stdout.w < 2 {
w = 2
}
if h+me.stdout.h < 2 {
h = 2
}
w0 := w
h0 := h
w1 := w + me.stdout.w
@ -143,8 +134,7 @@ func (tk *guiWidget) relocateStdout(w int, h int) {
tk.full.h0 = h0
tk.full.h1 = h1
me.baseGui.SetView("msg", w0, h0, w1, h1, 0)
// me.baseGui.SetViewOnBottom("msg")
tk.SetView()
}
// from the gocui devs:
@ -221,7 +211,9 @@ func (tk *guiWidget) refreshStdout() {
// chop off the last lines in the buffer
chop := len(me.stdout.outputS) - (me.stdout.pager + me.stdout.h)
cur = append(cur, me.stdout.outputS[chop:chop+me.stdout.h]...)
if me.stdout.reverse {
slices.Reverse(cur)
}
tk.v.Clear()
fmt.Fprintln(tk.v, strings.Join(cur, "\n"))
}

View File

@ -120,6 +120,7 @@ type stdout struct {
outputS []string // the buffer of all the output
pager int // allows the user to page through the buffer
changed bool // indicates the user has changed stdout. gocui should remember the state here
reverse bool // flip the STDOUT upside down so new STDOUT lines are at the top
}
// settings for the dropdown window

View File

@ -7,6 +7,7 @@ package main
import (
"strings"
"time"
"github.com/awesome-gocui/gocui"
log "go.wit.com/log"
@ -40,7 +41,7 @@ func initTextbox() {
func (callertk *guiWidget) prepTextbox() {
initTextbox()
if me.textbox.tk == nil {
log.Log(GOCUI, "prepTextbox() Is Broken")
log.Log(WARN, "prepTextbox() Is Broken")
return
}
@ -51,21 +52,35 @@ func (callertk *guiWidget) prepTextbox() {
r.w1 = r.w0 + 24
r.h1 = r.h0 + 2
me.textbox.tk.forceSizes(r)
// me.textbox.tk.dumpWidget("after sizes")
me.textbox.tk.dumpWidget("after sizes")
me.textbox.callerTK = callertk
// showTextbox(callertk.String())
if me.textbox.tk.v != nil {
log.Log(WARN, "WARNING textbox DeleteView()")
log.Log(WARN, "WARNING textbox DeleteView()")
log.Log(WARN, "WARNING textbox DeleteView()")
me.baseGui.DeleteView(me.textbox.tk.cuiName)
time.Sleep(time.Second)
}
if err := me.textbox.tk.SetViewRect(r); err != nil {
log.Log(WARN, "textbox SetViewRect() failed", err, "view name =", me.textbox.tk.cuiName)
return
}
// me.textbox.tk.Show() // actually makes the gocui view. TODO: redo this?
showTextbox(callertk.String())
}
func showTextbox(callers string) {
// tk := me.textbox.tk
// me.textbox.tk.dumpWidget("after sizes")
log.Log(WARN, "showTextbox() caller string =", callers)
// me.textbox.tk.Show() // actually makes the gocui view. TODO: redo this
if me.textbox.tk.v == nil {
log.Info("wtf went wrong")
log.Log(WARN, "textbox.tk.v == nil showTextbox() is broken")
return
}
@ -78,8 +93,8 @@ func showTextbox(callers string) {
me.textbox.tk.v.Editable = true
me.textbox.tk.v.Wrap = true
r := me.textbox.tk.gocuiSize
me.baseGui.SetView(me.textbox.tk.cuiName, r.w0, r.h0, r.w1, r.h1, 0)
me.textbox.tk.SetView()
me.baseGui.SetCurrentView(me.textbox.tk.v.Name())
// bind the enter key to a function so we can close the textbox
@ -87,7 +102,8 @@ func showTextbox(callers string) {
me.textbox.active = true
// me.textbox.dumpWidget("showTextbox()")
me.baseGui.SetViewOnTop(me.textbox.tk.v.Name())
me.textbox.tk.dumpWidget("showTextbox()")
}
func theCloseTheTextbox(g *gocui.Gui, v *gocui.View) error {

View File

@ -100,6 +100,7 @@ func (tk *guiWidget) redrawWindow(w int, h int) {
// set the window frame below the window widget, but this resizes the window widget it seems
me.baseGui.SetViewBeneath(tk.windowFrame.cuiName, tk.cuiName, 1)
// so now we have to resize the window frame, but this moves it to the top?
me.baseGui.SetView(tk.windowFrame.cuiName, tk.windowFrame.full.w0, tk.windowFrame.full.h0, tk.windowFrame.full.w1, tk.windowFrame.full.h1, 0)
@ -209,13 +210,6 @@ func (tk *guiWidget) makeWindowActive() {
tk.redrawWindow(tk.gocuiSize.w0, tk.gocuiSize.h0)
setThingsOnTop() // sets help, Stdout, etc on the top after windows have been redrawn
/*
// print out the window list
for _, tk := range me.allwin {
log.Info("makeWindowActive() Window", tk.labelN, tk.window.active, tk.window.order)
}
*/
}
func (tk *guiWidget) makeTK(ddItems []string) {
@ -226,25 +220,7 @@ func (tk *guiWidget) makeTK(ddItems []string) {
tk.gocuiSize.w1 = 120
tk.gocuiSize.h0 = 15
tk.gocuiSize.h1 = 18
/*
var err error
tk.v, err = me.baseGui.SetView(tk.cuiName,
tk.gocuiSize.w0,
tk.gocuiSize.h0,
tk.gocuiSize.w1,
tk.gocuiSize.h1, 0)
if err != nil {
log.Info("makeTK() err", err)
return
}
if tk.v == nil {
return
}
tk.v.Wrap = true
tk.v.Frame = true
tk.v.Clear()
fmt.Fprint(tk.v, items)
*/
tk.Show()
}