gocui: standard close

Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
Jeff Carr 2023-04-26 21:36:56 -05:00
parent 4e8a1bc432
commit a4403975e7
5 changed files with 18 additions and 22 deletions

View File

@ -75,21 +75,19 @@ func addDebugKeys(g *gocui.Gui) {
// exit // exit
g.SetKeybinding("", 'q', gocui.ModNone, g.SetKeybinding("", 'q', gocui.ModNone,
func(g *gocui.Gui, v *gocui.View) error { func(g *gocui.Gui, v *gocui.View) error {
me.baseGui.Close() standardExit()
sendBackQuit()
return nil return nil
}) })
g.SetKeybinding("", gocui.KeyCtrlC, gocui.ModNone, g.SetKeybinding("", gocui.KeyCtrlC, gocui.ModNone,
func(g *gocui.Gui, v *gocui.View) error { func(g *gocui.Gui, v *gocui.View) error {
me.baseGui.Close() standardExit()
sendBackQuit()
return nil return nil
}) })
// panic // panic
g.SetKeybinding("", 'p', gocui.ModNone, g.SetKeybinding("", 'p', gocui.ModNone,
func(g *gocui.Gui, v *gocui.View) error { func(g *gocui.Gui, v *gocui.View) error {
me.baseGui.Close() standardExit()
panic("forced panic in gocui") panic("forced panic in gocui")
return nil return nil
}) })

View File

@ -60,10 +60,17 @@ func catchActionChannel() {
func Exit() { func Exit() {
// TODO: what should actually happen here? // TODO: what should actually happen here?
me.baseGui.Close() standardExit()
sendBackQuit()
} }
func standardExit() {
me.baseGui.Close()
outf.Close()
setOutput(os.Stdout)
sendBackQuit()
sleep(.5)
exit()
}
func sendBackQuit() { func sendBackQuit() {
// send 'Quit' back to the program (?) // send 'Quit' back to the program (?)
var a toolkit.Action var a toolkit.Action
@ -89,7 +96,5 @@ func main() {
MouseMain() MouseMain()
log(true, "MouseMain() closed") log(true, "MouseMain() closed")
me.baseGui.Close() standardExit()
sendBackQuit()
} }

View File

@ -1,16 +1,11 @@
package main package main
import ( import (
"os"
// if you include more than just this import // if you include more than just this import
// then your plugin might be doing something un-ideal (just a guess from 2023/02/27) // then your plugin might be doing something un-ideal (just a guess from 2023/02/27)
"git.wit.org/wit/gui/toolkit" "git.wit.org/wit/gui/toolkit"
) )
func Quit() {
me.baseGui.Close()
}
func action(a *toolkit.Action) { func action(a *toolkit.Action) {
log(logInfo, "action() START", a.WidgetId, a.ActionType, a.WidgetType, a.Name) log(logInfo, "action() START", a.WidgetId, a.ActionType, a.WidgetType, a.Name)
w := findWidget(a.WidgetId, me.rootNode) 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) log(logNow, "attempt to move() =", a.ActionType, a.WidgetType, a.Name)
case toolkit.CloseToolkit: case toolkit.CloseToolkit:
log(logNow, "attempting to close the plugin and release stdout and stderr") log(logNow, "attempting to close the plugin and release stdout and stderr")
me.baseGui.Close() standardExit()
// defer outf.Close()
setOutput(os.Stdout)
default: default:
log(logError, "action() Unknown =", a.ActionType, a.WidgetType, a.Name) log(logError, "action() Unknown =", a.ActionType, a.WidgetType, a.Name)
} }

View File

@ -8,8 +8,8 @@ import (
"git.wit.org/wit/gui/toolkit" "git.wit.org/wit/gui/toolkit"
) )
var outputW int = 200 var outputW int = 180
var outputH int = 36 var outputH int = 24
func moveMsg(g *gocui.Gui) { func moveMsg(g *gocui.Gui) {
mx, my := g.MousePosition() mx, my := g.MousePosition()

View File

@ -220,8 +220,8 @@ func (w *cuiWidget) Write(p []byte) (n int, err error) {
s = strings.TrimSuffix(s, "\n") s = strings.TrimSuffix(s, "\n")
tmp := strings.Split(s, "\n") tmp := strings.Split(s, "\n")
outputS = append(outputS, tmp...) outputS = append(outputS, tmp...)
if (len(outputS) > 50) { if (len(outputS) > outputH) {
outputS = outputS[10:] outputS = outputS[4:]
} }
fmt.Fprintln(me.logStdout.v, strings.Join(outputS, "\n")) fmt.Fprintln(me.logStdout.v, strings.Join(outputS, "\n"))