summaryrefslogtreecommitdiff
path: root/toolkit
diff options
context:
space:
mode:
authorJeff Carr <[email protected]>2023-04-27 00:10:23 -0500
committerJeff Carr <[email protected]>2023-04-27 00:10:23 -0500
commitf5468d9c1cdaf1b0a2e44fcc78621bfae23e44fa (patch)
treef4da96c8302f70a8c683fae58ed568653f51cf2f /toolkit
parentefa1b7eba77254d2607dae47e3e6ea70fc619932 (diff)
gocui: better output handlingv0.8.4
Signed-off-by: Jeff Carr <[email protected]>
Diffstat (limited to 'toolkit')
-rw-r--r--toolkit/gocui/help.go39
-rw-r--r--toolkit/gocui/keybindings.go8
-rw-r--r--toolkit/gocui/structs.go26
-rw-r--r--toolkit/widget.go1
4 files changed, 48 insertions, 26 deletions
diff --git a/toolkit/gocui/help.go b/toolkit/gocui/help.go
index cf4e84d..74143a2 100644
--- a/toolkit/gocui/help.go
+++ b/toolkit/gocui/help.go
@@ -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
}
diff --git a/toolkit/gocui/keybindings.go b/toolkit/gocui/keybindings.go
index 2a6a982..cf948fe 100644
--- a/toolkit/gocui/keybindings.go
+++ b/toolkit/gocui/keybindings.go
@@ -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,
diff --git a/toolkit/gocui/structs.go b/toolkit/gocui/structs.go
index 4b1749e..09d1f33 100644
--- a/toolkit/gocui/structs.go
+++ b/toolkit/gocui/structs.go
@@ -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
}
diff --git a/toolkit/widget.go b/toolkit/widget.go
index f3d4773..38d4afc 100644
--- a/toolkit/widget.go
+++ b/toolkit/widget.go
@@ -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 {