save the output window state

This commit is contained in:
Jeff Carr 2025-03-25 07:27:37 -05:00
parent 4523eda0fa
commit 1552eedc18
11 changed files with 76 additions and 20 deletions

View File

@ -86,6 +86,9 @@ func (tk *guiWidget) dumpWidget(s string) {
} else {
end = fmt.Sprintf("%-8s %-8s %s", tk.WidgetType(), tk.cuiName, tk.String())
}
if tk.findParentTable() != nil {
end += " (table)"
}
log.Log(GOCUI, s1, s, end)
}

View File

@ -8,12 +8,14 @@ import (
"github.com/awesome-gocui/gocui"
"go.wit.com/log"
"go.wit.com/toolkits/tree"
)
func theStdout(g *gocui.Gui, v *gocui.View) error {
// me.stdout.pager = 0
infos := fmt.Sprintf("pager=%d len(%d) ", me.stdout.pager, len(me.stdout.outputS))
infos += fmt.Sprintf("last(%d,%d)", me.stdout.lastW, me.stdout.lastH)
me.stdout.changed = true
if me.stdout.outputOnTop {
if me.stdout.outputOffscreen {
@ -22,18 +24,38 @@ func theStdout(g *gocui.Gui, v *gocui.View) error {
me.stdout.lastW = me.stdout.tk.gocuiSize.w0
me.stdout.lastH = me.stdout.tk.gocuiSize.h0
relocateStdoutOffscreen()
new1 := new(tree.ToolkitConfig)
new1.Plugin = "gocui"
new1.Name = "stdoutoffscreen"
new1.Value = "true"
me.myTree.ConfigSave(new1)
return nil
} else {
me.stdout.outputOffscreen = true
log.Info("stdout moved on screen", infos)
new1 := new(tree.ToolkitConfig)
new1.Plugin = "gocui"
new1.Name = "stdoutoffscreen"
new1.Value = "false"
me.myTree.ConfigSave(new1)
}
// move the stdout window back onscreen
me.stdout.tk.relocateStdout(me.stdout.lastW, me.stdout.lastH)
me.stdout.outputOnTop = false
setThingsOnTop()
new1 := new(tree.ToolkitConfig)
new1.Plugin = "gocui"
new1.Name = "stdoutlevel"
new1.Value = "bottom"
me.myTree.ConfigSave(new1)
} else {
me.stdout.outputOnTop = true
setThingsOnTop()
new1 := new(tree.ToolkitConfig)
new1.Plugin = "gocui"
new1.Name = "stdoutlevel"
new1.Value = "top"
me.myTree.ConfigSave(new1)
}
return nil
}

View File

@ -48,6 +48,7 @@ func mouseMove(g *gocui.Gui) {
// old hack. create the 'msg' view if it does not yet exist
// TODO: put this somewhere more correct
if widgetView, _ := g.View("msg"); widgetView == nil {
me.stdout.changed = true
if createStdout(g) {
return
}
@ -138,5 +139,6 @@ func (tk *guiWidget) moveNew() {
// log.Info("Resize false", w, h, newW, newH)
}
setThingsOnTop() // sets help, Stdout, etc on the top after windows have been redrawn
me.stdout.changed = true
}
}

14
find.go
View File

@ -186,6 +186,20 @@ func (tk *guiWidget) findParentWindow() *guiWidget {
return tk.parent.findParentWindow()
}
func (tk *guiWidget) findParentTable() *guiWidget {
if tk.isTable {
log.Info("findParentTAble()", tk.labelN, tk.cuiName, tk.node.WidgetId)
return tk
}
if tk.node.WidgetId == 0 {
return nil
}
if tk.parent == nil {
return nil
}
return tk.parent.findParentWindow()
}
func (tk *guiWidget) findWidgetByName(name string) *guiWidget {
if tk.cuiName == name {
return tk

28
init.go
View File

@ -14,10 +14,13 @@ import (
"runtime"
"runtime/debug"
"runtime/pprof"
"strconv"
"strings"
"time"
"github.com/awesome-gocui/gocui"
"go.wit.com/log"
"go.wit.com/toolkits/tree"
)
// sent via -ldflags
@ -184,6 +187,19 @@ func initPlugin() {
me.stdout.lastW = 4
me.stdout.lastH = 20
if val, err := me.myTree.ConfigFind("stdoutsize"); err == nil {
parts := strings.Fields(val)
if len(parts) == 4 {
log.Info("initial stdout settings:", parts)
me.stdout.w, _ = strconv.Atoi(parts[0])
me.stdout.h, _ = strconv.Atoi(parts[1])
me.stdout.lastW, _ = strconv.Atoi(parts[2])
me.stdout.lastH, _ = strconv.Atoi(parts[3])
} else {
log.Info("initial stdout settings parse error:", parts)
}
}
// just make up unique values for these
me.dropdown.wId = -77
me.textbox.wId = -55
@ -376,6 +392,18 @@ func refreshGocui() {
me.newWindowTrigger <- me.treeRoot.TK.(*guiWidget)
me.refresh = false
}
if me.stdout.changed {
log.Log(NOW, "newWindowTrigger() TODO: gocui should save the stdout size & location here")
me.stdout.changed = false
me.stdout.tk.dumpWidget("save")
new1 := new(tree.ToolkitConfig)
new1.Plugin = "gocui"
new1.Name = "stdoutsize"
width := me.stdout.tk.gocuiSize.w1 - me.stdout.tk.gocuiSize.w0
height := me.stdout.tk.gocuiSize.h1 - me.stdout.tk.gocuiSize.h0
new1.Value = fmt.Sprintf("%d %d %d %d", width, height, me.stdout.tk.gocuiSize.w0, me.stdout.tk.gocuiSize.h0)
me.myTree.ConfigSave(new1)
}
}
// this code updates the clock

View File

@ -16,7 +16,7 @@ func newAdd(n *tree.Node) {
return
}
if n.TK != nil {
log.Warn("Tree Add() sent a widget we aleady seem to have")
log.Log(INFO, "Tree Add() sent a widget we aleady seem to have")
// this is done to protect the plugin being 'refreshed' with the
// widget binary tree. TODO: find a way to keep them in sync
return

View File

@ -116,11 +116,10 @@ type stdout struct {
disable bool // disable the stdout window. do not change os.Stdout & os.Stderr
lastW int // the last 'w' location (used to move from offscreen to onscreen)
lastH int // the last 'h' location (used to move from offscreen to onscreen)
// mouseOffsetW int // the current 'w' offset
// mouseOffsetH int // the current 'h' offset
init bool // moves the window offscreen on startup
outputS []string // the buffer of all the output
pager int // allows the user to page through the buffer
init bool // moves the window offscreen on startup
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
}
// settings for the dropdown window
@ -241,6 +240,7 @@ type guiWidget struct {
color *colorT // what color to use
colorLast colorT // the last color the widget had
defaultColor *colorT // the default colors // TODO: make a function for this instead
isTable bool // is this a table?
}
// THIS IS GO COMPILER MAGIC

View File

@ -13,20 +13,6 @@ import (
"go.wit.com/widget"
)
/*
func initGridPB(pb *guipb.Widget) *guiWidget {
var w *guiWidget
w = new(guiWidget)
w.pb = pb
w.parent = me.treeRoot.TK.(*guiWidget)
w.wtype = widget.Window
w.cuiName = fmt.Sprintf("%d %s", pb.Id, "TK")
w.labelN = pb.Name
return w
}
*/
func initGridPB(pb *guipb.Widget) *guiWidget {
var w *guiWidget
w = new(guiWidget)
@ -35,6 +21,7 @@ func initGridPB(pb *guipb.Widget) *guiWidget {
w.wtype = widget.Grid
w.cuiName = fmt.Sprintf("%d %s", pb.Id, "TK")
w.labelN = pb.Name
w.isTable = true
return w
}