2024-11-14 21:48:44 -06:00
|
|
|
//gjcarro:pjcarrlugin
|
|
|
|
|
2024-01-18 00:08:37 -06:00
|
|
|
// Copyright 2014 The gocui Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
2024-11-14 21:48:44 -06:00
|
|
|
|
2024-01-18 00:08:37 -06:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2024-02-01 21:47:31 -06:00
|
|
|
"errors"
|
2024-01-18 00:08:37 -06:00
|
|
|
"os"
|
2024-01-30 03:17:15 -06:00
|
|
|
"runtime/debug"
|
2024-01-18 00:08:37 -06:00
|
|
|
|
2024-02-01 21:47:31 -06:00
|
|
|
"github.com/awesome-gocui/gocui"
|
2024-01-18 00:08:37 -06:00
|
|
|
"go.wit.com/log"
|
2024-01-28 02:20:31 -06:00
|
|
|
"go.wit.com/toolkits/tree"
|
2024-01-18 00:08:37 -06:00
|
|
|
)
|
|
|
|
|
2024-02-09 09:30:23 -06:00
|
|
|
func queueToolkitClose() {
|
|
|
|
me.baseGui.Close()
|
|
|
|
}
|
|
|
|
|
|
|
|
func queueSetChecked(n *tree.Node, b bool) {
|
|
|
|
setChecked(n, b)
|
|
|
|
}
|
|
|
|
|
2024-01-18 00:08:37 -06:00
|
|
|
// sets defaults and establishes communication
|
|
|
|
// to this toolkit from the wit/gui golang package
|
|
|
|
func init() {
|
|
|
|
log.Log(INFO, "Init() of awesome-gocui")
|
|
|
|
|
|
|
|
// init the config struct default values
|
|
|
|
Set(&me, "default")
|
|
|
|
|
2024-01-29 23:39:33 -06:00
|
|
|
// Set(&me, "dense")
|
|
|
|
|
2024-01-28 02:20:31 -06:00
|
|
|
me.myTree = tree.New()
|
|
|
|
me.myTree.PluginName = "gocui"
|
2024-02-05 12:27:22 -06:00
|
|
|
|
2024-02-05 09:04:38 -06:00
|
|
|
me.myTree.NodeAction = newaction
|
|
|
|
me.myTree.Add = newAdd
|
|
|
|
me.myTree.SetTitle = newSetTitle
|
|
|
|
me.myTree.SetLabel = newSetLabel
|
|
|
|
me.myTree.SetText = newSetText
|
|
|
|
me.myTree.AddText = newAddText
|
2024-02-09 09:30:23 -06:00
|
|
|
me.myTree.SetChecked = queueSetChecked
|
|
|
|
me.myTree.ToolkitClose = queueToolkitClose
|
2024-01-18 00:08:37 -06:00
|
|
|
|
|
|
|
log.Log(NOW, "Init() start pluginChan")
|
|
|
|
log.Sleep(.1) // probably not needed, but in here for now under development
|
2024-01-30 03:17:15 -06:00
|
|
|
go mainGogui()
|
2024-01-18 00:08:37 -06:00
|
|
|
log.Sleep(.1) // probably not needed, but in here for now under development
|
|
|
|
}
|
|
|
|
|
|
|
|
func standardExit() {
|
|
|
|
log.Log(NOW, "standardExit() doing baseGui.Close()")
|
|
|
|
me.baseGui.Close()
|
|
|
|
log.Log(NOW, "standardExit() doing outf.Close()")
|
|
|
|
outf.Close()
|
|
|
|
// log(true, "standardExit() setOutput(os.Stdout)")
|
|
|
|
// setOutput(os.Stdout)
|
|
|
|
log.Log(NOW, "standardExit() send back Quit()")
|
2024-01-28 02:20:31 -06:00
|
|
|
// go sendBackQuit() // don't stall here in case the
|
2024-01-18 00:08:37 -06:00
|
|
|
// induces a delay in case the callback channel is broken
|
|
|
|
log.Sleep(1)
|
|
|
|
log.Log(NOW, "standardExit() exit()")
|
|
|
|
os.Exit(0)
|
|
|
|
}
|
|
|
|
|
2024-01-30 11:54:57 -06:00
|
|
|
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()")
|
|
|
|
}
|
|
|
|
|
2024-01-18 00:08:37 -06:00
|
|
|
var outf *os.File
|
|
|
|
|
|
|
|
func main() {
|
2024-01-30 03:17:15 -06:00
|
|
|
}
|
|
|
|
|
2024-02-01 20:12:26 -06:00
|
|
|
var origStdout *os.File
|
|
|
|
var origStderr *os.File
|
|
|
|
|
2024-01-30 03:17:15 -06:00
|
|
|
func mainGogui() {
|
|
|
|
defer func() {
|
|
|
|
if r := recover(); r != nil {
|
|
|
|
log.Warn("YAHOOOO Recovered in guiMain application:", r)
|
|
|
|
log.Warn("Recovered from panic:", r)
|
2024-02-01 09:41:16 -06:00
|
|
|
me.baseGui.Close()
|
2024-11-13 21:03:50 -06:00
|
|
|
log.CaptureMode(nil)
|
|
|
|
log.Warn("YAHOOOO Recovered in guiMain application:", r)
|
|
|
|
log.Warn("Recovered from panic:", r)
|
2024-02-09 10:27:36 -06:00
|
|
|
me.myTree.SendToolkitPanic()
|
2024-02-01 21:47:31 -06:00
|
|
|
|
2024-01-30 03:17:15 -06:00
|
|
|
return
|
|
|
|
}
|
|
|
|
}()
|
2024-11-13 21:03:50 -06:00
|
|
|
|
2024-01-18 00:08:37 -06:00
|
|
|
var err error
|
|
|
|
|
2024-11-13 21:03:50 -06:00
|
|
|
outf, err = os.OpenFile("/tmp/captureMode.log", os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666)
|
2024-01-18 00:08:37 -06:00
|
|
|
if err != nil {
|
|
|
|
log.Error(err, "error opening file: %v")
|
|
|
|
os.Exit(0)
|
|
|
|
}
|
2024-02-01 20:12:26 -06:00
|
|
|
origStdout = os.Stdout
|
2024-01-18 00:08:37 -06:00
|
|
|
os.Stdout = outf
|
|
|
|
defer outf.Close()
|
|
|
|
|
2024-11-13 21:03:50 -06:00
|
|
|
log.CaptureMode(outf)
|
2024-01-18 00:08:37 -06:00
|
|
|
|
|
|
|
gocuiMain()
|
|
|
|
}
|
2024-02-01 21:47:31 -06:00
|
|
|
|
|
|
|
// This initializes the gocui package
|
|
|
|
// it runs SetManagerFunc which passes every input
|
|
|
|
// event (keyboard, mouse, etc) to the function "gocuiEvent()"
|
|
|
|
func gocuiMain() {
|
2024-02-02 11:47:32 -06:00
|
|
|
defer func() {
|
|
|
|
if r := recover(); r != nil {
|
|
|
|
log.Warn("YAHOOOO Recovered in gocuiMain()", r)
|
|
|
|
log.Warn("Recovered from panic:", r)
|
|
|
|
me.baseGui.Close()
|
|
|
|
|
|
|
|
// allow gocui to close if possible, then print stack
|
|
|
|
log.Sleep(1)
|
|
|
|
os.Stdout = origStdout
|
|
|
|
os.Stderr = origStderr
|
|
|
|
me.myTree.SendToolkitPanic()
|
|
|
|
log.Warn("Stack trace:")
|
|
|
|
debug.PrintStack()
|
2024-02-02 14:49:17 -06:00
|
|
|
// panic("BUMMER 2")
|
2024-02-02 11:47:32 -06:00
|
|
|
|
|
|
|
// attempt to switch to the nocui toolkit
|
|
|
|
log.Sleep(1)
|
|
|
|
me.myTree.SendToolkitLoad("nocui")
|
2024-02-05 15:03:35 -06:00
|
|
|
log.Sleep(3)
|
|
|
|
me.myTree.SendToolkitLoad("nocui")
|
2024-02-02 11:47:32 -06:00
|
|
|
// panic("BUMMER")
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}()
|
2024-02-01 21:47:31 -06:00
|
|
|
g, err := gocui.NewGui(gocui.OutputNormal, true)
|
|
|
|
if err != nil {
|
2024-02-02 11:47:32 -06:00
|
|
|
return
|
2024-02-01 21:47:31 -06:00
|
|
|
}
|
|
|
|
defer g.Close()
|
|
|
|
|
|
|
|
me.baseGui = g
|
|
|
|
|
|
|
|
g.Cursor = true
|
|
|
|
g.Mouse = true
|
|
|
|
|
|
|
|
// this sets the function that is run on every event. For example:
|
|
|
|
// When you click the mouse, move the mouse, or press a key on the keyboard
|
|
|
|
// This is equivalent to xev or similar to cat /dev/input on linux
|
|
|
|
g.SetManagerFunc(gocuiEvent)
|
|
|
|
|
|
|
|
if err := defaultKeybindings(g); err != nil {
|
2024-02-02 11:47:32 -06:00
|
|
|
// normally panic here
|
2024-02-02 11:58:33 -06:00
|
|
|
log.Log(NOW, "defaultKeybindings(g) panic err =", err)
|
|
|
|
panic("gocuiTKdefaultkeybindings OOPS")
|
2024-02-01 21:47:31 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
if err := g.MainLoop(); err != nil && !errors.Is(err, gocui.ErrQuit) {
|
2024-02-02 11:58:33 -06:00
|
|
|
log.Log(NOW, "g.MainLoop() panic err =", err)
|
2024-02-02 11:47:32 -06:00
|
|
|
// normally panic here
|
2024-02-02 11:58:33 -06:00
|
|
|
panic("gocuiTKmainloop OOPS")
|
2024-02-01 21:47:31 -06:00
|
|
|
}
|
|
|
|
}
|