From a4403975e79a76619a5990dda85d6b18b90b1209 Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Wed, 26 Apr 2023 21:36:56 -0500 Subject: [PATCH] gocui: standard close Signed-off-by: Jeff Carr --- toolkit/gocui/keybindings.go | 8 +++----- toolkit/gocui/main.go | 15 ++++++++++----- toolkit/gocui/plugin.go | 9 +-------- toolkit/gocui/showStdout.go | 4 ++-- toolkit/gocui/structs.go | 4 ++-- 5 files changed, 18 insertions(+), 22 deletions(-) diff --git a/toolkit/gocui/keybindings.go b/toolkit/gocui/keybindings.go index 66c098b..2a6a982 100644 --- a/toolkit/gocui/keybindings.go +++ b/toolkit/gocui/keybindings.go @@ -75,21 +75,19 @@ func addDebugKeys(g *gocui.Gui) { // exit g.SetKeybinding("", 'q', gocui.ModNone, func(g *gocui.Gui, v *gocui.View) error { - me.baseGui.Close() - sendBackQuit() + standardExit() return nil }) g.SetKeybinding("", gocui.KeyCtrlC, gocui.ModNone, func(g *gocui.Gui, v *gocui.View) error { - me.baseGui.Close() - sendBackQuit() + standardExit() return nil }) // panic g.SetKeybinding("", 'p', gocui.ModNone, func(g *gocui.Gui, v *gocui.View) error { - me.baseGui.Close() + standardExit() panic("forced panic in gocui") return nil }) diff --git a/toolkit/gocui/main.go b/toolkit/gocui/main.go index 4b66153..0dd2c0a 100644 --- a/toolkit/gocui/main.go +++ b/toolkit/gocui/main.go @@ -60,10 +60,17 @@ func catchActionChannel() { func Exit() { // TODO: what should actually happen here? - me.baseGui.Close() - sendBackQuit() + standardExit() } +func standardExit() { + me.baseGui.Close() + outf.Close() + setOutput(os.Stdout) + sendBackQuit() + sleep(.5) + exit() +} func sendBackQuit() { // send 'Quit' back to the program (?) var a toolkit.Action @@ -89,7 +96,5 @@ func main() { MouseMain() log(true, "MouseMain() closed") - me.baseGui.Close() - - sendBackQuit() + standardExit() } diff --git a/toolkit/gocui/plugin.go b/toolkit/gocui/plugin.go index f204e09..27d96b9 100644 --- a/toolkit/gocui/plugin.go +++ b/toolkit/gocui/plugin.go @@ -1,16 +1,11 @@ package main import ( - "os" // if you include more than just this import // then your plugin might be doing something un-ideal (just a guess from 2023/02/27) "git.wit.org/wit/gui/toolkit" ) -func Quit() { - me.baseGui.Close() -} - func action(a *toolkit.Action) { log(logInfo, "action() START", a.WidgetId, a.ActionType, a.WidgetType, a.Name) w := findWidget(a.WidgetId, me.rootNode) @@ -41,9 +36,7 @@ func action(a *toolkit.Action) { log(logNow, "attempt to move() =", a.ActionType, a.WidgetType, a.Name) case toolkit.CloseToolkit: log(logNow, "attempting to close the plugin and release stdout and stderr") - me.baseGui.Close() - // defer outf.Close() - setOutput(os.Stdout) + standardExit() default: log(logError, "action() Unknown =", a.ActionType, a.WidgetType, a.Name) } diff --git a/toolkit/gocui/showStdout.go b/toolkit/gocui/showStdout.go index f028587..909abd5 100644 --- a/toolkit/gocui/showStdout.go +++ b/toolkit/gocui/showStdout.go @@ -8,8 +8,8 @@ import ( "git.wit.org/wit/gui/toolkit" ) -var outputW int = 200 -var outputH int = 36 +var outputW int = 180 +var outputH int = 24 func moveMsg(g *gocui.Gui) { mx, my := g.MousePosition() diff --git a/toolkit/gocui/structs.go b/toolkit/gocui/structs.go index c6cd248..d3d8b03 100644 --- a/toolkit/gocui/structs.go +++ b/toolkit/gocui/structs.go @@ -220,8 +220,8 @@ func (w *cuiWidget) Write(p []byte) (n int, err error) { s = strings.TrimSuffix(s, "\n") tmp := strings.Split(s, "\n") outputS = append(outputS, tmp...) - if (len(outputS) > 50) { - outputS = outputS[10:] + if (len(outputS) > outputH) { + outputS = outputS[4:] } fmt.Fprintln(me.logStdout.v, strings.Join(outputS, "\n"))