gocui/showStdout.go

118 lines
2.7 KiB
Go

package main
import (
"errors"
"fmt"
"github.com/awesome-gocui/gocui"
"go.wit.com/log"
"go.wit.com/widget"
)
var outputW int = 180
var outputH int = 24
func moveMsg(g *gocui.Gui) {
mx, my := g.MousePosition()
if !movingMsg && (mx != initialMouseX || my != initialMouseY) {
movingMsg = true
}
g.SetView("msg", mx-xOffset, my-yOffset, mx-xOffset+outputW, my-yOffset+outputH+me.FramePadH, 0)
me.startOutputW = mx - xOffset
me.startOutputH = my - yOffset
g.SetViewOnBottom("msg")
}
func showMsg(g *gocui.Gui, v *gocui.View) error {
var l string
var err error
log.Log(NOW, "showMsg() v.name =", v.Name())
if _, err := g.SetCurrentView(v.Name()); err != nil {
return err
}
_, cy := v.Cursor()
if l, err = v.Line(cy); err != nil {
l = ""
}
makeOutputWidget(g, l)
return nil
}
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 {
a := new(widget.Action)
a.ProgName = "stdout"
a.WidgetType = widget.Stdout
a.WidgetId = -3
a.ParentId = 0
// n := addNode(a)
n := me.myTree.AddNode(a)
n.TK = initWidget(n)
me.logStdout = n
var tk *guiWidget
tk = me.logStdout.TK.(*guiWidget)
// tk.gocuiSize.w0 = maxX - 32
// tk.gocuiSize.h0 = maxY / 2
tk.gocuiSize.w0 = me.startOutputW
tk.gocuiSize.h0 = me.startOutputH
tk.gocuiSize.w1 = tk.gocuiSize.w0 + outputW
tk.gocuiSize.h1 = tk.gocuiSize.h0 + outputH
}
v, err := g.View("msg")
if v == nil {
log.Log(NOW, "makeoutputwindow() this is supposed to happen. v == nil", err)
} else {
log.Log(NOW, "makeoutputwindow() msg != nil. WTF now? err =", err)
}
// help, err := g.SetView("help", maxX-32, 0, maxX-1, 13, 0)
// v, err = g.SetView("msg", 3, 3, 30, 30, 0)
if me.startOutputW == 0 {
me.startOutputW = maxX - 32
}
if me.startOutputW == 0 {
me.startOutputH = maxY / 2
}
// v, err = g.SetView("msg", maxX-32, maxY/2, maxX/2+outputW, maxY/2+outputH, 0)
v, err = g.SetView("msg", me.startOutputW, me.startOutputH, maxX/2+outputW, maxY/2+outputH, 0)
if errors.Is(err, gocui.ErrUnknownView) {
log.Log(NOW, "makeoutputwindow() this is supposed to happen?", err)
}
if err != nil {
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 {
var tk *guiWidget
tk = me.logStdout.TK.(*guiWidget)
tk.v = v
}
v.Clear()
v.SelBgColor = gocui.ColorCyan
v.SelFgColor = gocui.ColorBlack
fmt.Fprintln(v, "figure out how to capture STDOUT to here\n"+stringFromMouseClick)
g.SetViewOnBottom("msg")
// g.SetViewOnBottom(v.Name())
return v
}