summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeff Carr <[email protected]>2025-02-07 16:44:01 -0600
committerJeff Carr <[email protected]>2025-02-07 16:44:01 -0600
commita295aa420b00e071510e7586d797cee6217f144e (patch)
tree452cbaf266cdeb01929100af5d1c9caef35e57d7
parentd8353f9b1a917cb12cdc19e68d73415f1679abd8 (diff)
remember stdout location on restore
-rw-r--r--eventBindings.go54
-rw-r--r--eventBindingsStdout.go78
-rw-r--r--size.go10
-rw-r--r--stdoutShow.go2
4 files changed, 93 insertions, 51 deletions
diff --git a/eventBindings.go b/eventBindings.go
index e17d9b6..eaec4d1 100644
--- a/eventBindings.go
+++ b/eventBindings.go
@@ -4,7 +4,6 @@
package main
import (
- "fmt"
"syscall"
"github.com/awesome-gocui/gocui"
@@ -37,8 +36,13 @@ func registerHandlers(g *gocui.Gui) {
g.SetKeybinding("", 'D', gocui.ModNone, theDarkness) // 'D' toggles light/dark mode
g.SetKeybinding("", 'q', gocui.ModNone, doExit) // 'q' exit
g.SetKeybinding("", gocui.KeyTab, gocui.ModNone, tabCycleWindows) // '2' use this to test new ideas
- g.SetKeybinding("", gocui.KeyPgup, gocui.ModNone, stdoutPgup) // Pgup scroll up the Stdout buffer
- g.SetKeybinding("", gocui.KeyPgdn, gocui.ModNone, stdoutPgdn) // Pgdn scroll down the Stdout buffer
+
+ // stdout keys
+ g.SetKeybinding("", gocui.KeyPgup, gocui.ModNone, stdoutPgup) // Pgup scroll up the Stdout buffer
+ g.SetKeybinding("", gocui.KeyPgdn, gocui.ModNone, stdoutPgdn) // Pgdn scroll down the Stdout buffer
+ g.SetKeybinding("", gocui.KeyHome, gocui.ModNone, stdoutHome) // Pgdn scroll down the Stdout buffer
+ g.SetKeybinding("", gocui.KeyArrowUp, gocui.ModNone, stdoutArrowUp) // Pgdn scroll down the Stdout buffer
+ g.SetKeybinding("", gocui.KeyArrowDown, gocui.ModNone, stdoutArrowDown) // Pgdn scroll down the Stdout buffer
// debugging
g.SetKeybinding("", '2', gocui.ModNone, theNotsure) // '2' use this to test new ideas
@@ -92,24 +96,6 @@ func theDarkness(g *gocui.Gui, v *gocui.View) error {
return nil
}
-func stdoutPgup(g *gocui.Gui, v *gocui.View) error {
- me.stdout.pager -= 40
- if me.stdout.pager < 0 {
- me.stdout.pager = 0
- }
- tk := me.stdout.tk
- tk.refreshStdout()
- return nil
-}
-
-func stdoutPgdn(g *gocui.Gui, v *gocui.View) error {
- me.stdout.pager += 10
-
- tk := me.stdout.tk
- tk.refreshStdout()
- return nil
-}
-
func wheelsUp(g *gocui.Gui, v *gocui.View) error {
log.Info("private wheels up")
return nil
@@ -139,32 +125,6 @@ func tabCycleWindows(g *gocui.Gui, v *gocui.View) error {
return nil
}
-func theStdout(g *gocui.Gui, v *gocui.View) error {
- me.stdout.pager = 0
- if me.stdout.outputOnTop {
- if me.stdout.outputOffscreen {
- me.stdout.outputOffscreen = false
- log.Info(fmt.Sprintf("stdout moved off screen pager=%d len(%d)", me.stdout.pager, len(me.stdout.outputS)))
- relocateStdoutOffscreen()
- return nil
- } else {
- me.stdout.outputOffscreen = true
- log.Info(fmt.Sprintf("stdout moved on screen pager=%d len(%d)", me.stdout.pager, len(me.stdout.outputS)))
- }
- // move the stdout window back onscreen
- me.stdout.tk.relocateStdout(me.stdout.lastW, me.stdout.lastH)
- me.stdout.outputOnTop = false
- setThingsOnTop()
- // me.baseGui.SetViewOnBottom("msg")
- // setBottomBG()
- } else {
- me.stdout.outputOnTop = true
- setThingsOnTop()
- // me.baseGui.SetViewOnTop("msg")
- }
- return nil
-}
-
func theShow(g *gocui.Gui, v *gocui.View) error {
var w *guiWidget
w = me.treeRoot.TK.(*guiWidget)
diff --git a/eventBindingsStdout.go b/eventBindingsStdout.go
new file mode 100644
index 0000000..1347c5c
--- /dev/null
+++ b/eventBindingsStdout.go
@@ -0,0 +1,78 @@
+// Copyright 2017-2025 WIT.COM Inc. All rights reserved.
+// Use of this source code is governed by the GPL 3.0
+
+package main
+
+import (
+ "fmt"
+
+ "github.com/awesome-gocui/gocui"
+ "go.wit.com/log"
+)
+
+func theStdout(g *gocui.Gui, v *gocui.View) error {
+ // me.stdout.pager = 0
+ infos := fmt.Sprintf("stdout moved off screen pager=%d len(%d) ", me.stdout.pager, len(me.stdout.outputS))
+ infos += fmt.Sprintf("last(%d,%d)", me.stdout.lastW, me.stdout.lastH)
+
+ if me.stdout.outputOnTop {
+ if me.stdout.outputOffscreen {
+ me.stdout.outputOffscreen = false
+ log.Info("stdout moved off screen", infos)
+ me.stdout.lastW = me.stdout.tk.gocuiSize.w0
+ me.stdout.lastH = me.stdout.tk.gocuiSize.h0
+ relocateStdoutOffscreen()
+ return nil
+ } else {
+ me.stdout.outputOffscreen = true
+ log.Info("stdout moved on screen", infos)
+ }
+ // move the stdout window back onscreen
+ me.stdout.tk.relocateStdout(me.stdout.lastW, me.stdout.lastH)
+ me.stdout.outputOnTop = false
+ setThingsOnTop()
+ // me.baseGui.SetViewOnBottom("msg")
+ // setBottomBG()
+ } else {
+ me.stdout.outputOnTop = true
+ setThingsOnTop()
+ // me.baseGui.SetViewOnTop("msg")
+ }
+ return nil
+}
+
+func stdoutPgup(g *gocui.Gui, v *gocui.View) error {
+ me.stdout.pager -= 40
+ if me.stdout.pager < 0 {
+ me.stdout.pager = 0
+ }
+ tk := me.stdout.tk
+ tk.refreshStdout()
+ return nil
+}
+
+func stdoutHome(g *gocui.Gui, v *gocui.View) error {
+ me.stdout.pager = 0
+ me.stdout.tk.refreshStdout()
+ return nil
+}
+
+func stdoutArrowUp(g *gocui.Gui, v *gocui.View) error {
+ me.stdout.pager += 1
+ me.stdout.tk.refreshStdout()
+ return nil
+}
+
+func stdoutArrowDown(g *gocui.Gui, v *gocui.View) error {
+ me.stdout.pager -= 1
+ me.stdout.tk.refreshStdout()
+ return nil
+}
+
+func stdoutPgdn(g *gocui.Gui, v *gocui.View) error {
+ me.stdout.pager += 10
+
+ tk := me.stdout.tk
+ tk.refreshStdout()
+ return nil
+}
diff --git a/size.go b/size.go
index 064d2ae..47af74d 100644
--- a/size.go
+++ b/size.go
@@ -76,7 +76,7 @@ func (tk *guiWidget) Size() (int, int) {
case widget.Label:
return len(tk.String()) + 2, 1
case widget.Textbox:
- return len(tk.String()) + 2, 3 // TODO: compute this based on 'window dense'
+ return len(tk.String()) + 10, 3 // TODO: compute this based on 'window dense'
case widget.Checkbox:
return len(tk.String()) + 2, 3 // TODO: compute this based on 'window dense'
}
@@ -341,9 +341,13 @@ func (tk *guiWidget) getFullSize() rectType {
// the full size is exactly what gocui uses
switch tk.node.WidgetType {
case widget.Label:
- return tk.buttonFullSize()
+ r := tk.buttonFullSize()
+ r.w1 += 5
+ return r
case widget.Button:
- return tk.buttonFullSize()
+ r := tk.buttonFullSize()
+ r.w1 += 5
+ return r
case widget.Checkbox:
return tk.buttonFullSize()
case widget.Dropdown:
diff --git a/stdoutShow.go b/stdoutShow.go
index b8767ac..f74bf80 100644
--- a/stdoutShow.go
+++ b/stdoutShow.go
@@ -179,7 +179,7 @@ func (w *guiWidget) Write(p []byte) (n int, err error) {
// lets the user page up and down through the stdout buffer
func (tk *guiWidget) refreshStdout() {
if len(me.stdout.outputS) < me.stdout.h+me.stdout.pager {
- log.Info(fmt.Sprintf("buffer too small=%d len(%d)", me.stdout.pager, len(me.stdout.outputS)))
+ // log.Info(fmt.Sprintf("buffer too small=%d len(%d)", me.stdout.pager, len(me.stdout.outputS)))
return
}