gocui: better output handling
Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
parent
17b59b7e7e
commit
b789fbbe56
|
@ -139,7 +139,7 @@ Creates a window helpful for debugging this package
|
|||
|
||||
`func ShowDebugValues()`
|
||||
|
||||
### func [StandardExit](/main.go#L191)
|
||||
### func [StandardExit](/main.go#L197)
|
||||
|
||||
`func StandardExit()`
|
||||
|
||||
|
@ -180,7 +180,7 @@ var Config GuiConfig
|
|||
The Node is a binary tree. This is how all GUI elements are stored
|
||||
simply the name and the size of whatever GUI element exists
|
||||
|
||||
#### func [New](/main.go#L162)
|
||||
#### func [New](/main.go#L168)
|
||||
|
||||
`func New() *Node`
|
||||
|
||||
|
|
|
@ -19,7 +19,7 @@ var myButton *Node
|
|||
Creates a window helpful for debugging this package
|
||||
*/
|
||||
func DebugWindow() {
|
||||
bugWin = Config.rootNode.NewWindow("go.wit.org/gui debug window").DebugTab("Debug Tab")
|
||||
bugWin = Config.rootNode.NewWindow("go.wit.com/gui debug window").DebugTab("Debug Tab")
|
||||
bugWin.Custom = bugWin.StandardClose
|
||||
// bugWin.DebugTab("Debug Tab")
|
||||
}
|
||||
|
|
12
main.go
12
main.go
|
@ -53,13 +53,19 @@ func watchCallback() {
|
|||
log(logNow, "watchCallback() restarted select for toolkit user events")
|
||||
select {
|
||||
case a := <-Config.guiChan:
|
||||
n := Config.rootNode.FindId(a.WidgetId)
|
||||
if (a.ActionType == toolkit.UserQuit) {
|
||||
log(logNow, "doUserEvent() node =", n.id, n.Name, "User sent Quit()")
|
||||
n.doCustom()
|
||||
log(logNow, "doUserEvent() User sent Quit()")
|
||||
Config.rootNode.doCustom()
|
||||
exit("wit/gui toolkit.UserQuit")
|
||||
break
|
||||
}
|
||||
if (a.ActionType == toolkit.EnableDebug) {
|
||||
log(logNow, "doUserEvent() Enable Debugging Window")
|
||||
DebugWindow()
|
||||
break
|
||||
}
|
||||
|
||||
n := Config.rootNode.FindId(a.WidgetId)
|
||||
if (n == nil) {
|
||||
log(logError, "watchCallback() UNKNOWN widget id =", a.WidgetId, a.Name)
|
||||
} else {
|
||||
|
|
|
@ -7,6 +7,7 @@ package main
|
|||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/awesome-gocui/gocui"
|
||||
)
|
||||
|
@ -15,33 +16,45 @@ func addHelp() {
|
|||
me.baseGui.SetManagerFunc(helplayout)
|
||||
}
|
||||
|
||||
var helpText []string = []string{"KEYBINDINGS",
|
||||
"",
|
||||
"d: show/hide debugging",
|
||||
"h: hide widgets",
|
||||
"s: show all widgets",
|
||||
"q: quit()",
|
||||
"p: panic()",
|
||||
"o: show Stdout",
|
||||
"l: log to /tmp/witgui.log",
|
||||
"Ctrl-D: Enable Debugging",
|
||||
"Ctrl-C: Exit",
|
||||
"",
|
||||
}
|
||||
|
||||
func helplayout(g *gocui.Gui) error {
|
||||
var err error
|
||||
maxX, _ := g.Size()
|
||||
|
||||
help, err := g.SetView("help", maxX-32, 0, maxX-1, 13, 0)
|
||||
var newW int = 8
|
||||
for _, s := range(helpText) {
|
||||
if newW < len(s) {
|
||||
newW = len(s)
|
||||
}
|
||||
}
|
||||
|
||||
help, err := g.SetView("help", maxX-(newW + me.FramePadW), 0, maxX-1, len(helpText) + me.FramePadH, 0)
|
||||
if err != nil {
|
||||
if !errors.Is(err, gocui.ErrUnknownView) {
|
||||
return err
|
||||
}
|
||||
help.SelBgColor = gocui.ColorGreen
|
||||
help.SelFgColor = gocui.ColorBlack
|
||||
fmt.Fprintln(help, "KEYBINDINGS")
|
||||
// fmt.Fprintln(help, "Enter: Click Button")
|
||||
// fmt.Fprintln(help, "Tab/Space: Switch Buttons")
|
||||
fmt.Fprintln(help, "")
|
||||
// fmt.Fprintln(help, "h: Help")
|
||||
// fmt.Fprintln(help, "Backspace: Delete Button")
|
||||
// fmt.Fprintln(help, "Arrow keys: Move Button")
|
||||
// fmt.Fprintln(help, "t: Move Button to the top")
|
||||
// fmt.Fprintln(help, "b: Move Button to the button")
|
||||
fmt.Fprintln(help, "d: show/hide debugging")
|
||||
fmt.Fprintln(help, "h: hide widgets")
|
||||
fmt.Fprintln(help, "s: show all widgets")
|
||||
fmt.Fprintln(help, "q: quit()")
|
||||
fmt.Fprintln(help, "p: panic()")
|
||||
fmt.Fprintln(help, "STDOUT: /tmp/witgui.log")
|
||||
// fmt.Fprintln(help, "Ctrl-C: Exit") // TODO: fix ctrl-c handling
|
||||
|
||||
fmt.Fprintln(help, strings.Join(helpText, "\n"))
|
||||
|
||||
if _, err := g.SetCurrentView("help"); err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -6,6 +6,7 @@ package main
|
|||
|
||||
import (
|
||||
"github.com/awesome-gocui/gocui"
|
||||
"git.wit.org/wit/gui/toolkit"
|
||||
)
|
||||
|
||||
func defaultKeybindings(g *gocui.Gui) error {
|
||||
|
@ -83,6 +84,13 @@ func addDebugKeys(g *gocui.Gui) {
|
|||
standardExit()
|
||||
return nil
|
||||
})
|
||||
g.SetKeybinding("", gocui.KeyCtrlD, gocui.ModNone,
|
||||
func(g *gocui.Gui, v *gocui.View) error {
|
||||
var a toolkit.Action
|
||||
a.ActionType = toolkit.EnableDebug
|
||||
me.callback <- a
|
||||
return nil
|
||||
})
|
||||
|
||||
// panic
|
||||
g.SetKeybinding("", 'p', gocui.ModNone,
|
||||
|
|
|
@ -204,27 +204,27 @@ func (w *cuiWidget) Write(p []byte) (n int, err error) {
|
|||
me.writeMutex.Lock()
|
||||
defer me.writeMutex.Unlock()
|
||||
if (me.logStdout.v == nil) {
|
||||
// optionally write the output to /tmp
|
||||
fmt.Fprintln(outf, string(p))
|
||||
v, _ := me.baseGui.View("msg")
|
||||
if (v != nil) {
|
||||
fmt.Fprintln(outf, "found msg")
|
||||
me.logStdout.v = v
|
||||
}
|
||||
return
|
||||
}
|
||||
me.logStdout.v.Clear()
|
||||
// fmt.Fprintln(w.v, p + "jcarr")
|
||||
// log(logNow, "widget.Write()", p)
|
||||
} else {
|
||||
// display the output in the gocui window
|
||||
me.logStdout.v.Clear()
|
||||
|
||||
s := fmt.Sprint(string(p))
|
||||
s = "jwc " + strconv.Itoa(len(outputS)) + " " + strings.TrimSuffix(s, "\n")
|
||||
tmp := strings.Split(s, "\n")
|
||||
outputS = append(outputS, tmp...)
|
||||
if (len(outputS) > outputH) {
|
||||
l := len(outputS) - outputH
|
||||
outputS = outputS[l:]
|
||||
s := fmt.Sprint(string(p))
|
||||
s = strings.TrimSuffix(s, "\n")
|
||||
tmp := strings.Split(s, "\n")
|
||||
outputS = append(outputS, tmp...)
|
||||
if (len(outputS) > outputH) {
|
||||
l := len(outputS) - outputH
|
||||
outputS = outputS[l:]
|
||||
}
|
||||
fmt.Fprintln(me.logStdout.v, strings.Join(outputS, "\n"))
|
||||
}
|
||||
fmt.Fprintln(me.logStdout.v, strings.Join(outputS, "\n"))
|
||||
|
||||
return len(p), nil
|
||||
}
|
||||
|
|
|
@ -95,6 +95,7 @@ const (
|
|||
InitToolkit // initializes the toolkit
|
||||
CloseToolkit // closes the toolkit
|
||||
UserQuit // the user closed the GUI
|
||||
EnableDebug // open the debugging window
|
||||
)
|
||||
|
||||
func (s WidgetType) String() string {
|
||||
|
|
Loading…
Reference in New Issue