From 3f2f3de751ed9863ab798853b2a09db6b745a1b0 Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Tue, 30 Jan 2024 11:54:57 -0600 Subject: [PATCH] try to get toolkit to close Signed-off-by: Jeff Carr --- keybindings.go | 2 +- main.go | 20 +++++++++++++------- plugin.go | 2 +- 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/keybindings.go b/keybindings.go index f798fdb..9059f72 100644 --- a/keybindings.go +++ b/keybindings.go @@ -172,7 +172,7 @@ func addDebugKeys(g *gocui.Gui) { // panic g.SetKeybinding("", 'p', gocui.ModNone, func(g *gocui.Gui, v *gocui.View) error { - standardExit() + standardClose() panic("forced panic in gocui") return nil }) diff --git a/main.go b/main.go index b2c0fd7..8e75031 100644 --- a/main.go +++ b/main.go @@ -35,12 +35,6 @@ func init() { log.Sleep(.1) // probably not needed, but in here for now under development } -func Exit() { - // TODO: what should actually happen here? - log.Log(NOW, "Exit() here. doing standardExit()") - standardExit() -} - func standardExit() { log.Log(NOW, "standardExit() doing baseGui.Close()") me.baseGui.Close() @@ -56,6 +50,17 @@ func standardExit() { os.Exit(0) } +func standardClose() { + log.Log(NOW, "standardExit() doing baseGui.Close()") + me.baseGui.Close() + log.Log(NOW, "standardExit() doing outf.Close()") + outf.Close() + os.Stdin = os.Stdin + os.Stdout = os.Stdout + os.Stderr = os.Stderr + log.Log(NOW, "standardExit() send back Quit()") +} + var outf *os.File func main() { @@ -66,9 +71,10 @@ func mainGogui() { if r := recover(); r != nil { log.Warn("YAHOOOO Recovered in guiMain application:", r) log.Warn("Recovered from panic:", r) + me.myTree.SendToolkitPanic() log.Warn("Stack trace:") debug.PrintStack() - me.myTree.SendToolkitPanic() + // panic("BUMMER") return } }() diff --git a/plugin.go b/plugin.go index c8bd88c..204b77a 100644 --- a/plugin.go +++ b/plugin.go @@ -82,7 +82,7 @@ func action(a widget.Action) { log.Log(NOW, "attempt to move() =", a.ActionType, a.WidgetType, a.ProgName) case widget.ToolkitClose: log.Log(NOW, "attempting to close the plugin and release stdout and stderr") - standardExit() + standardClose() case widget.Enable: w.enable = true w.enableColor()