diff --git a/eventGocui.go b/eventGocui.go index 7999f14..5c7ef3d 100644 --- a/eventGocui.go +++ b/eventGocui.go @@ -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") diff --git a/libnotify.go b/libnotify.go index 679d2ba..8e282d5 100644 --- a/libnotify.go +++ b/libnotify.go @@ -207,15 +207,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 +225,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 +245,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") - } - return + 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) } - 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 +276,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() } diff --git a/plugin.go b/plugin.go index 67def55..5356a64 100644 --- a/plugin.go +++ b/plugin.go @@ -200,7 +200,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 diff --git a/stdoutShow.go b/stdoutShow.go index 1f6e5a6..429294c 100644 --- a/stdoutShow.go +++ b/stdoutShow.go @@ -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: diff --git a/textbox.go b/textbox.go index f385245..424397d 100644 --- a/textbox.go +++ b/textbox.go @@ -7,6 +7,7 @@ package main import ( "strings" + "time" "github.com/awesome-gocui/gocui" log "go.wit.com/log" @@ -55,20 +56,16 @@ func (callertk *guiWidget) prepTextbox() { me.textbox.callerTK = callertk - /* - 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 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) + } - var err error - me.textbox.tk.v, err = me.baseGui.SetView(me.textbox.tk.cuiName, r.w0, r.h0, r.w1, r.h1, 0) - if err != nil { - log.Log(WARN, "textbox SetView() failed", err, "view name =", me.textbox.tk.cuiName) + 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? @@ -96,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 diff --git a/window.go b/window.go index 043f109..a45fc1d 100644 --- a/window.go +++ b/window.go @@ -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) @@ -211,10 +212,10 @@ func (tk *guiWidget) makeWindowActive() { 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) - } + // print out the window list // TODO: put this in libnotify + for _, tk := range me.allwin { + log.Info("makeWindowActive() Window", tk.labelN, tk.window.active, tk.window.order) + } */ } @@ -226,25 +227,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() }