remember stdout location on restore

This commit is contained in:
Jeff Carr 2025-02-07 16:44:01 -06:00
parent d8353f9b1a
commit a295aa420b
4 changed files with 93 additions and 51 deletions

View File

@ -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
// 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)

78
eventBindingsStdout.go Normal file
View File

@ -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
}

10
size.go
View File

@ -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:

View File

@ -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
}