add config default to show stdout onscreen on start
This commit is contained in:
parent
90083d5bcb
commit
c4f9bac85e
|
@ -69,26 +69,11 @@ func theSuperMouse(g *gocui.Gui, v *gocui.View) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
/*
|
||||
func addDropdown() *tree.Node {
|
||||
return addDropdownNew(-222)
|
||||
}
|
||||
*/
|
||||
|
||||
// use this to test code ideas // put whatever you want here and hit '2' to activate it
|
||||
func theNotsure(g *gocui.Gui, v *gocui.View) error {
|
||||
log.Info("got keypress 2. now what? dark =", me.dark)
|
||||
if me.clock.tk == nil {
|
||||
me.clock.tk = makeNewFlagWidget(me.clock.wId)
|
||||
me.clock.tk.dumpWidget("init() clock")
|
||||
w, h := me.baseGui.MousePosition()
|
||||
me.clock.tk.MoveToOffset(w, h)
|
||||
me.clock.tk.labelN = time.Now().Format("15:04:05")
|
||||
me.clock.tk.frame = false
|
||||
me.clock.tk.setColorLabel()
|
||||
me.clock.tk.Show()
|
||||
me.clock.active = true
|
||||
me.clock.tk.dumpWidget("showClock()")
|
||||
makeClock()
|
||||
} else {
|
||||
me.clock.tk.v.Clear()
|
||||
me.clock.tk.labelN = time.Now().Format("15:04:05")
|
||||
|
|
|
@ -12,7 +12,7 @@ import (
|
|||
|
||||
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("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 {
|
||||
|
@ -25,7 +25,7 @@ func theStdout(g *gocui.Gui, v *gocui.View) error {
|
|||
return nil
|
||||
} else {
|
||||
me.stdout.outputOffscreen = true
|
||||
log.Info("stdout moved on screen", infos)
|
||||
log.Info("stdout moved on screen", infos)
|
||||
}
|
||||
// move the stdout window back onscreen
|
||||
me.stdout.tk.relocateStdout(me.stdout.lastW, me.stdout.lastH)
|
||||
|
|
|
@ -143,6 +143,7 @@ func doMouseClick(w int, h int) {
|
|||
}
|
||||
me.myTree.SendUserEvent(tk.node)
|
||||
case widget.Button:
|
||||
tk.dumpWidget("click()") // enable this to debug widget clicks
|
||||
me.myTree.SendFromUser(tk.node)
|
||||
return
|
||||
case widget.Combobox:
|
||||
|
|
29
help.go
29
help.go
|
@ -11,6 +11,7 @@ import (
|
|||
"errors"
|
||||
"fmt"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/awesome-gocui/gocui"
|
||||
log "go.wit.com/log"
|
||||
|
@ -85,8 +86,13 @@ func showHelp() error {
|
|||
}
|
||||
g.SetViewOnTop("help")
|
||||
me.helpLabel = help
|
||||
if me.clock.tk == nil {
|
||||
makeClock()
|
||||
me.clock.tk.MoveToOffset(maxX-10, 1)
|
||||
me.clock.tk.Hide()
|
||||
me.clock.tk.Show()
|
||||
}
|
||||
if me.clock.tk != nil {
|
||||
g.SetView("help", maxX-(newW+me.FramePadW), 0, maxX-1, len(helpText)+me.FramePadH, 0)
|
||||
me.clock.tk.MoveToOffset(maxX-10, 1)
|
||||
me.clock.tk.Hide()
|
||||
me.clock.tk.Show()
|
||||
|
@ -94,6 +100,19 @@ func showHelp() error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func makeClock() {
|
||||
me.clock.tk = makeNewFlagWidget(me.clock.wId)
|
||||
me.clock.tk.dumpWidget("init() clock")
|
||||
w, h := me.baseGui.MousePosition()
|
||||
me.clock.tk.MoveToOffset(w, h)
|
||||
me.clock.tk.labelN = time.Now().Format("15:04:05")
|
||||
me.clock.tk.frame = false
|
||||
me.clock.tk.setColorLabel()
|
||||
me.clock.tk.Show()
|
||||
me.clock.active = true
|
||||
me.clock.tk.dumpWidget("showClock()")
|
||||
}
|
||||
|
||||
// in the very end of redrawing things, this will place the help and stdout on the top or botton
|
||||
// depending on the state the user has chosen
|
||||
func setThingsOnTop() {
|
||||
|
@ -102,6 +121,9 @@ func setThingsOnTop() {
|
|||
} else {
|
||||
me.baseGui.SetViewOnTop("help")
|
||||
}
|
||||
if me.clock.tk != nil {
|
||||
me.baseGui.SetViewOnTop(me.clock.tk.v.Name())
|
||||
}
|
||||
|
||||
if me.dark {
|
||||
me.stdout.tk.v.FgColor = gocui.ColorWhite
|
||||
|
@ -116,6 +138,11 @@ func setThingsOnTop() {
|
|||
} else {
|
||||
me.baseGui.SetViewOnBottom("msg")
|
||||
}
|
||||
if me.stdout.startOnscreen {
|
||||
log.Info("attempting to locate stdout on screen for the first time")
|
||||
me.stdout.tk.relocateStdout(me.stdout.lastW, me.stdout.lastH)
|
||||
me.stdout.startOnscreen = false
|
||||
}
|
||||
setBottomBG()
|
||||
}
|
||||
|
||||
|
|
10
init.go
10
init.go
|
@ -59,6 +59,15 @@ func init() {
|
|||
me.myTree.PluginName = "gocui"
|
||||
go refreshGocui()
|
||||
|
||||
// read in defaults from config protobuf
|
||||
if val, err := me.myTree.ConfigFind("stdout"); err == nil {
|
||||
if val == "true" {
|
||||
me.stdout.startOnscreen = true
|
||||
me.stdout.Write([]byte("starting with stdout onscreen\n"))
|
||||
} else {
|
||||
me.stdout.Write([]byte("starting with stdout offscreen\n"))
|
||||
}
|
||||
}
|
||||
if val, err := me.myTree.ConfigFind("dark"); err == nil {
|
||||
if val == "true" {
|
||||
me.dark = true
|
||||
|
@ -202,6 +211,7 @@ func gocuiMain() {
|
|||
// registered event handlers still have the events sent to gocuiEvent() above
|
||||
registerHandlers(g)
|
||||
|
||||
me.stdout.Write([]byte("begin gogui.MainLoop()\n"))
|
||||
if err := g.MainLoop(); err != nil && !errors.Is(err, gocui.ErrQuit) {
|
||||
log.Log(NOW, "g.MainLoop() panic err =", err)
|
||||
// normally panic here
|
||||
|
|
|
@ -95,6 +95,13 @@ func makeOutputWidget(g *gocui.Gui, stringFromMouseClick string) *gocui.View {
|
|||
me.stdout.tk.v = v
|
||||
me.stdout.tk.DrawAt(me.stdout.lastW, me.stdout.lastH)
|
||||
relocateStdoutOffscreen()
|
||||
/*
|
||||
if me.stdout.outputOffscreen {
|
||||
me.stdout.tk.relocateStdout(me.stdout.lastW, me.stdout.lastH)
|
||||
} else {
|
||||
relocateStdoutOffscreen()
|
||||
}
|
||||
*/
|
||||
return v
|
||||
}
|
||||
|
||||
|
@ -135,12 +142,24 @@ func (tk *guiWidget) relocateStdout(w int, h int) {
|
|||
// of functions like fmt.Fprintf, fmt.Fprintln, io.Copy, etc. Clear must
|
||||
// be called to clear the view's buffer.
|
||||
|
||||
func (w stdout) Write(p []byte) (n int, err error) {
|
||||
me.writeMutex.Lock()
|
||||
defer me.writeMutex.Unlock()
|
||||
|
||||
lines := strings.Split(strings.TrimSpace(string(p)), "\n")
|
||||
me.stdout.outputS = append(me.stdout.outputS, lines...)
|
||||
|
||||
return len(p), nil
|
||||
}
|
||||
|
||||
func (w *guiWidget) Write(p []byte) (n int, err error) {
|
||||
w.tainted = true
|
||||
me.writeMutex.Lock()
|
||||
defer me.writeMutex.Unlock()
|
||||
|
||||
tk := me.stdout.tk
|
||||
lines := strings.Split(strings.TrimSpace(string(p)), "\n")
|
||||
me.stdout.outputS = append(me.stdout.outputS, lines...)
|
||||
|
||||
if tk.v == nil {
|
||||
// optionally write the output to /tmp
|
||||
|
@ -154,9 +173,6 @@ func (w *guiWidget) Write(p []byte) (n int, err error) {
|
|||
}
|
||||
} else {
|
||||
// display the output in the gocui window
|
||||
lines := strings.Split(strings.TrimSpace(string(p)), "\n")
|
||||
me.stdout.outputS = append(me.stdout.outputS, lines...)
|
||||
|
||||
var cur []string
|
||||
// chop off the last lines in the buffer
|
||||
chop := len(me.stdout.outputS) - (me.stdout.h - 1)
|
||||
|
|
|
@ -96,6 +96,7 @@ type stdout struct {
|
|||
h int // the height
|
||||
outputOnTop bool // is the STDOUT window on top?
|
||||
outputOffscreen bool // is the STDOUT window offscreen?
|
||||
startOnscreen bool // start the output window onscreen?
|
||||
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
|
||||
|
|
Loading…
Reference in New Issue