diff --git a/README-goreadme.md b/README-goreadme.md index 2aa5bf2..26dbce4 100644 --- a/README-goreadme.md +++ b/README-goreadme.md @@ -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` diff --git a/debugWindow.go b/debugWindow.go index e55a911..01273c8 100644 --- a/debugWindow.go +++ b/debugWindow.go @@ -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") } diff --git a/main.go b/main.go index e6efe86..21904ab 100644 --- a/main.go +++ b/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 { 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 {