stdout var cleanup

This commit is contained in:
Jeff Carr 2025-02-06 02:49:21 -06:00
parent 88e9594b93
commit 8522d4671e
5 changed files with 63 additions and 86 deletions

View File

@ -90,7 +90,7 @@ func (tk *guiWidget) dumpWidget(s string) {
func printWidgetTree(g *gocui.Gui, v *gocui.View) error {
me.treeRoot.ListWidgets()
tk := me.logStdout
tk := me.stdout.tk
// msg := fmt.Sprintf("test out kb %d\n", ecount)
// tk.Write([]byte(msg))
if tk == nil {

View File

@ -129,14 +129,6 @@ func (tk *guiWidget) moveNew() {
tk.full.w1 = w1
tk.full.h0 = h0
tk.full.h1 = h1
/* this totally fucks up stdout
me.logStdout.full.w0 = w - xOffset
me.logStdout.full.h0 = h - xOffset
me.logStdout.full.w1 = me.logStdout.full.w0 + 120 + me.logStdout.gocuiSize.Width()
me.logStdout.full.h1 = me.logStdout.full.h0 + 40 + me.logStdout.gocuiSize.Height()
me.logStdout.DrawAt(me.logStdout.full.w0, me.logStdout.full.h0)
*/
}
// always place the help menu on top
setThingsOnTop() // sets help, Stdout, etc on the top after windows have been redrawn
@ -144,10 +136,10 @@ func (tk *guiWidget) moveNew() {
func createStdout(g *gocui.Gui) bool {
makeOutputWidget(g, "this is a create before a mouse click")
if me.logStdout != nil {
if me.stdout.tk != nil {
msg := fmt.Sprintf("test out gocuiEvent() %d\n", me.ecount)
// me.logStdout.v.Write([]byte(msg))
me.logStdout.Write([]byte(msg))
me.stdout.tk.Write([]byte(msg))
log.Log(NOW, "logStdout test out")
}
return true

View File

@ -38,8 +38,11 @@ func init() {
// init the config struct default values
Set(&me, "default")
// initial stdout window settings
me.stdout.w = 180
me.stdout.h = 40
me.stdout.offsetW = 30
me.stdout.offsetH = 10
// Set(&me, "dense")

View File

@ -34,14 +34,12 @@ func showMsg(g *gocui.Gui, v *gocui.View) error {
}
func makeOutputWidget(g *gocui.Gui, stringFromMouseClick string) *gocui.View {
// maxX, maxY := g.Size()
if me.treeRoot == nil {
// keep skipping this until the binary tree is initialized
return nil
}
if me.logStdout == nil {
if me.stdout.tk == nil {
a := new(widget.Action)
a.ProgName = "stdout"
a.WidgetType = widget.Stdout
@ -49,13 +47,11 @@ func makeOutputWidget(g *gocui.Gui, stringFromMouseClick string) *gocui.View {
a.ParentId = 0
// n := addNode(a)
n := me.myTree.AddNode(a)
me.logStdout = initWidget(n)
me.stdout.tk = initWidget(n)
tk := me.logStdout
// tk.gocuiSize.w0 = maxX - 32
// tk.gocuiSize.h0 = maxY / 2
tk.gocuiSize.w0 = 30
tk.gocuiSize.h0 = 10
tk := me.stdout.tk
tk.gocuiSize.w0 = me.stdout.offsetW
tk.gocuiSize.h0 = me.stdout.offsetH
tk.gocuiSize.w1 = tk.gocuiSize.w0 + me.stdout.w
tk.gocuiSize.h1 = tk.gocuiSize.h0 + me.stdout.h
@ -68,21 +64,9 @@ func makeOutputWidget(g *gocui.Gui, stringFromMouseClick string) *gocui.View {
log.Log(NOW, "makeoutputwindow() msg != nil. WTF now? err =", err)
}
/*
if me.startOutputW == 0 {
me.startOutputW = maxX - 132
}
if me.startOutputW == 0 {
me.startOutputH = maxY / 2
}
*/
rect := me.stdout.tk.gocuiSize
v, err = g.SetView("msg", rect.w0, rect.h0, rect.w1, rect.h1, 0)
a := me.logStdout.gocuiSize.w0
b := me.logStdout.gocuiSize.h0
c := me.logStdout.gocuiSize.w1
d := me.logStdout.gocuiSize.h1
v, err = g.SetView("msg", a, b, c, d, 0)
// v, err = g.SetView("msg", me.startOutputW, me.startOutputH, maxX/2+me.stdout.w, maxY/2+me.stdout.h, 0)
if errors.Is(err, gocui.ErrUnknownView) {
log.Log(NOW, "makeoutputwindow() this is supposed to happen?", err)
}
@ -96,7 +80,7 @@ func makeOutputWidget(g *gocui.Gui, stringFromMouseClick string) *gocui.View {
log.Log(NOW, "makeoutputwindow() msg == nil. WTF now? err =", err)
return nil
} else {
me.logStdout.v = v
me.stdout.tk.v = v
}
v.Clear()
@ -105,7 +89,7 @@ func makeOutputWidget(g *gocui.Gui, stringFromMouseClick string) *gocui.View {
fmt.Fprintln(v, "figure out how to capture STDOUT to here\n"+stringFromMouseClick)
g.SetViewOnBottom("msg")
me.logStdout.v = v
me.logStdout.DrawAt(10, 10)
me.stdout.tk.v = v
me.stdout.tk.DrawAt(me.stdout.offsetW, me.stdout.offsetH)
return v
}

View File

@ -30,58 +30,56 @@ var redoWidgets bool = true // todo: move this into config struct
// todo: move all this to a protobuf. then, redo all this mess. it got me here, but now it's time to clean it up for good
type config struct {
baseGui *gocui.Gui // the main gocui handle
treeRoot *tree.Node // the base of the binary tree. it should have id == 0
myTree *tree.TreeInfo // ?
ctrlDown *tree.Node // shown if you click the mouse when the ctrl key is pressed
currentWindow *guiWidget // this is the current tab or window to show
logStdout *guiWidget // where to show STDOUT
// startOutputW int // ?
// startOutputH int // ?
helpLabel *gocui.View // ?
showHelp bool // toggle boolean for the help menu (deprecate?)
dropdownW *guiWidget // grab the dropdown choices from this widget
FramePadW int `default:"1" dense:"0"` // When the widget has a frame, like a button, it adds 2 lines runes on each side
FramePadH int `default:"1" dense:"0"` // When the widget has a frame, like a button, it adds 2 lines runes on each side
PadW int `default:"1" dense:"0"` // pad spacing
PadH int `default:"1" dense:"0"` // pad spacing
WindowW int `default:"8" dense:"0"` // how far down to start Window or Tab headings
WindowH int `default:"-1"` // how far down to start Window or Tab headings
TabW int `default:"5" dense:"0"` // how far down to start Window or Tab headings
TabH int `default:"1" dense:"0"` // how far down to start Window or Tab headings
WindowPadW int `default:"8" dense:"0"` // additional amount of space to put between window & tab widgets
TabPadW int `default:"4" dense:"0"` // additional amount of space to put between window & tab widgets
GroupPadW int `default:"2" dense:"1"` // additional amount of space to indent on a group
BoxPadW int `default:"2" dense:"1"` // additional amount of space to indent on a box
GridPadW int `default:"2" dense:"1"` // additional amount of space to indent on a grid
RawW int `default:"1"` // the raw beginning of each window (or tab)
RawH int `default:"5"` // the raw beginning of each window (or tab)
FakeW int `default:"20"` // offset for the hidden widgets
padded bool // add space between things like buttons
bookshelf bool // do you want things arranged in the box like a bookshelf or a stack?
canvas bool // if set to true, the windows are a raw canvas
menubar bool // for windows
stretchy bool // expand things like buttons to the maximum size
margin bool // add space around the frames of windows
writeMutex sync.Mutex // writeMutex protects writes to *guiWidget (it's global right now maybe)
dtoggle bool // is a dropdown or combobox currently active?
ecount int // counts how many mouse and keyboard events have occurred
supermouse bool // prints out every widget found while you move the mouse around
depth int // used for listWidgets() debugging
globalMouseDown bool // yep, mouse is pressed
newWindowTrigger chan bool // work around hack to redraw windows a bit after NewWindow()
stdout stdout // information for the STDOUT window
baseGui *gocui.Gui // the main gocui handle
treeRoot *tree.Node // the base of the binary tree. it should have id == 0
myTree *tree.TreeInfo // ?
ctrlDown *tree.Node // shown if you click the mouse when the ctrl key is pressed
currentWindow *guiWidget // this is the current tab or window to show
helpLabel *gocui.View // ?
showHelp bool // toggle boolean for the help menu (deprecate?)
dropdownW *guiWidget // grab the dropdown choices from this widget
FramePadW int `default:"1" dense:"0"` // When the widget has a frame, like a button, it adds 2 lines runes on each side
FramePadH int `default:"1" dense:"0"` // When the widget has a frame, like a button, it adds 2 lines runes on each side
PadW int `default:"1" dense:"0"` // pad spacing
PadH int `default:"1" dense:"0"` // pad spacing
WindowW int `default:"8" dense:"0"` // how far down to start Window or Tab headings
WindowH int `default:"-1"` // how far down to start Window or Tab headings
TabW int `default:"5" dense:"0"` // how far down to start Window or Tab headings
TabH int `default:"1" dense:"0"` // how far down to start Window or Tab headings
WindowPadW int `default:"8" dense:"0"` // additional amount of space to put between window & tab widgets
TabPadW int `default:"4" dense:"0"` // additional amount of space to put between window & tab widgets
GroupPadW int `default:"2" dense:"1"` // additional amount of space to indent on a group
BoxPadW int `default:"2" dense:"1"` // additional amount of space to indent on a box
GridPadW int `default:"2" dense:"1"` // additional amount of space to indent on a grid
RawW int `default:"1"` // the raw beginning of each window (or tab)
RawH int `default:"5"` // the raw beginning of each window (or tab)
FakeW int `default:"20"` // offset for the hidden widgets
padded bool // add space between things like buttons
bookshelf bool // do you want things arranged in the box like a bookshelf or a stack?
canvas bool // if set to true, the windows are a raw canvas
menubar bool // for windows
stretchy bool // expand things like buttons to the maximum size
margin bool // add space around the frames of windows
writeMutex sync.Mutex // writeMutex protects writes to *guiWidget (it's global right now maybe)
dtoggle bool // is a dropdown or combobox currently active?
ecount int // counts how many mouse and keyboard events have occurred
supermouse bool // prints out every widget found while you move the mouse around
depth int // used for listWidgets() debugging
globalMouseDown bool // yep, mouse is pressed
newWindowTrigger chan bool // work around hack to redraw windows a bit after NewWindow()
stdout stdout // information for the STDOUT window
}
// settings for the stdout window
type stdout struct {
w int // the width
h int // the width
outputOnTop bool // is the STDOUT window on top?
offscreenW int // where to place the window offscreen
offscreenH int // where to place the window offscreen
offsetW int // the current 'w' offset
offsetH int // the current 'h' offset
tk *guiWidget // where to show STDOUT
w int // the width
h int // the width
outputOnTop bool // is the STDOUT window on top?
offscreenW int // where to place the window offscreen
offscreenH int // where to place the window offscreen
offsetW int // the current 'w' offset
offsetH int // the current 'h' offset
}
// deprecate these
@ -154,7 +152,7 @@ func (w *guiWidget) Write(p []byte) (n int, err error) {
// _, outputH := w.Size()
outputH := 33 // special output length for "msg" window until I figure things out
tk := me.logStdout
tk := me.stdout.tk
if tk.v == nil {
// optionally write the output to /tmp
s := fmt.Sprint(string(p))