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
|
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
|
// 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 {
|
func theNotsure(g *gocui.Gui, v *gocui.View) error {
|
||||||
log.Info("got keypress 2. now what? dark =", me.dark)
|
log.Info("got keypress 2. now what? dark =", me.dark)
|
||||||
if me.clock.tk == nil {
|
if me.clock.tk == nil {
|
||||||
me.clock.tk = makeNewFlagWidget(me.clock.wId)
|
makeClock()
|
||||||
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()")
|
|
||||||
} else {
|
} else {
|
||||||
me.clock.tk.v.Clear()
|
me.clock.tk.v.Clear()
|
||||||
me.clock.tk.labelN = time.Now().Format("15:04:05")
|
me.clock.tk.labelN = time.Now().Format("15:04:05")
|
||||||
|
|
|
@ -12,7 +12,7 @@ import (
|
||||||
|
|
||||||
func theStdout(g *gocui.Gui, v *gocui.View) error {
|
func theStdout(g *gocui.Gui, v *gocui.View) error {
|
||||||
// me.stdout.pager = 0
|
// 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)
|
infos += fmt.Sprintf("last(%d,%d)", me.stdout.lastW, me.stdout.lastH)
|
||||||
|
|
||||||
if me.stdout.outputOnTop {
|
if me.stdout.outputOnTop {
|
||||||
|
@ -25,7 +25,7 @@ func theStdout(g *gocui.Gui, v *gocui.View) error {
|
||||||
return nil
|
return nil
|
||||||
} else {
|
} else {
|
||||||
me.stdout.outputOffscreen = true
|
me.stdout.outputOffscreen = true
|
||||||
log.Info("stdout moved on screen", infos)
|
log.Info("stdout moved on screen", infos)
|
||||||
}
|
}
|
||||||
// move the stdout window back onscreen
|
// move the stdout window back onscreen
|
||||||
me.stdout.tk.relocateStdout(me.stdout.lastW, me.stdout.lastH)
|
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)
|
me.myTree.SendUserEvent(tk.node)
|
||||||
case widget.Button:
|
case widget.Button:
|
||||||
|
tk.dumpWidget("click()") // enable this to debug widget clicks
|
||||||
me.myTree.SendFromUser(tk.node)
|
me.myTree.SendFromUser(tk.node)
|
||||||
return
|
return
|
||||||
case widget.Combobox:
|
case widget.Combobox:
|
||||||
|
|
29
help.go
29
help.go
|
@ -11,6 +11,7 @@ import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"strings"
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/awesome-gocui/gocui"
|
"github.com/awesome-gocui/gocui"
|
||||||
log "go.wit.com/log"
|
log "go.wit.com/log"
|
||||||
|
@ -85,8 +86,13 @@ func showHelp() error {
|
||||||
}
|
}
|
||||||
g.SetViewOnTop("help")
|
g.SetViewOnTop("help")
|
||||||
me.helpLabel = 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 {
|
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.MoveToOffset(maxX-10, 1)
|
||||||
me.clock.tk.Hide()
|
me.clock.tk.Hide()
|
||||||
me.clock.tk.Show()
|
me.clock.tk.Show()
|
||||||
|
@ -94,6 +100,19 @@ func showHelp() error {
|
||||||
return nil
|
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
|
// 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
|
// depending on the state the user has chosen
|
||||||
func setThingsOnTop() {
|
func setThingsOnTop() {
|
||||||
|
@ -102,6 +121,9 @@ func setThingsOnTop() {
|
||||||
} else {
|
} else {
|
||||||
me.baseGui.SetViewOnTop("help")
|
me.baseGui.SetViewOnTop("help")
|
||||||
}
|
}
|
||||||
|
if me.clock.tk != nil {
|
||||||
|
me.baseGui.SetViewOnTop(me.clock.tk.v.Name())
|
||||||
|
}
|
||||||
|
|
||||||
if me.dark {
|
if me.dark {
|
||||||
me.stdout.tk.v.FgColor = gocui.ColorWhite
|
me.stdout.tk.v.FgColor = gocui.ColorWhite
|
||||||
|
@ -116,6 +138,11 @@ func setThingsOnTop() {
|
||||||
} else {
|
} else {
|
||||||
me.baseGui.SetViewOnBottom("msg")
|
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()
|
setBottomBG()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
10
init.go
10
init.go
|
@ -59,6 +59,15 @@ func init() {
|
||||||
me.myTree.PluginName = "gocui"
|
me.myTree.PluginName = "gocui"
|
||||||
go refreshGocui()
|
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, err := me.myTree.ConfigFind("dark"); err == nil {
|
||||||
if val == "true" {
|
if val == "true" {
|
||||||
me.dark = true
|
me.dark = true
|
||||||
|
@ -202,6 +211,7 @@ func gocuiMain() {
|
||||||
// registered event handlers still have the events sent to gocuiEvent() above
|
// registered event handlers still have the events sent to gocuiEvent() above
|
||||||
registerHandlers(g)
|
registerHandlers(g)
|
||||||
|
|
||||||
|
me.stdout.Write([]byte("begin gogui.MainLoop()\n"))
|
||||||
if err := g.MainLoop(); err != nil && !errors.Is(err, gocui.ErrQuit) {
|
if err := g.MainLoop(); err != nil && !errors.Is(err, gocui.ErrQuit) {
|
||||||
log.Log(NOW, "g.MainLoop() panic err =", err)
|
log.Log(NOW, "g.MainLoop() panic err =", err)
|
||||||
// normally panic here
|
// normally panic here
|
||||||
|
|
|
@ -95,6 +95,13 @@ func makeOutputWidget(g *gocui.Gui, stringFromMouseClick string) *gocui.View {
|
||||||
me.stdout.tk.v = v
|
me.stdout.tk.v = v
|
||||||
me.stdout.tk.DrawAt(me.stdout.lastW, me.stdout.lastH)
|
me.stdout.tk.DrawAt(me.stdout.lastW, me.stdout.lastH)
|
||||||
relocateStdoutOffscreen()
|
relocateStdoutOffscreen()
|
||||||
|
/*
|
||||||
|
if me.stdout.outputOffscreen {
|
||||||
|
me.stdout.tk.relocateStdout(me.stdout.lastW, me.stdout.lastH)
|
||||||
|
} else {
|
||||||
|
relocateStdoutOffscreen()
|
||||||
|
}
|
||||||
|
*/
|
||||||
return v
|
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
|
// of functions like fmt.Fprintf, fmt.Fprintln, io.Copy, etc. Clear must
|
||||||
// be called to clear the view's buffer.
|
// 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) {
|
func (w *guiWidget) Write(p []byte) (n int, err error) {
|
||||||
w.tainted = true
|
w.tainted = true
|
||||||
me.writeMutex.Lock()
|
me.writeMutex.Lock()
|
||||||
defer me.writeMutex.Unlock()
|
defer me.writeMutex.Unlock()
|
||||||
|
|
||||||
tk := me.stdout.tk
|
tk := me.stdout.tk
|
||||||
|
lines := strings.Split(strings.TrimSpace(string(p)), "\n")
|
||||||
|
me.stdout.outputS = append(me.stdout.outputS, lines...)
|
||||||
|
|
||||||
if tk.v == nil {
|
if tk.v == nil {
|
||||||
// optionally write the output to /tmp
|
// optionally write the output to /tmp
|
||||||
|
@ -154,9 +173,6 @@ func (w *guiWidget) Write(p []byte) (n int, err error) {
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// display the output in the gocui window
|
// 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
|
var cur []string
|
||||||
// chop off the last lines in the buffer
|
// chop off the last lines in the buffer
|
||||||
chop := len(me.stdout.outputS) - (me.stdout.h - 1)
|
chop := len(me.stdout.outputS) - (me.stdout.h - 1)
|
||||||
|
|
|
@ -96,6 +96,7 @@ type stdout struct {
|
||||||
h int // the height
|
h int // the height
|
||||||
outputOnTop bool // is the STDOUT window on top?
|
outputOnTop bool // is the STDOUT window on top?
|
||||||
outputOffscreen bool // is the STDOUT window offscreen?
|
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)
|
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)
|
lastH int // the last 'h' location (used to move from offscreen to onscreen)
|
||||||
// mouseOffsetW int // the current 'w' offset
|
// mouseOffsetW int // the current 'w' offset
|
||||||
|
|
Loading…
Reference in New Issue