summaryrefslogtreecommitdiff
path: root/init.go
diff options
context:
space:
mode:
authorJeff Carr <[email protected]>2025-03-03 03:45:36 -0600
committerJeff Carr <[email protected]>2025-03-03 03:45:36 -0600
commit9ef16c1bf2bfc1e00163b461779383c809efff9f (patch)
tree2118e9596fbf3dce620766572aa203f87841a334 /init.go
parentda54c0f039fe35aef01dabeaf6267fd4e3ba377d (diff)
better tree init()
Diffstat (limited to 'init.go')
-rw-r--r--init.go110
1 files changed, 69 insertions, 41 deletions
diff --git a/init.go b/init.go
index 63bf765..425be56 100644
--- a/init.go
+++ b/init.go
@@ -96,22 +96,55 @@ func toolkitClose() {
me.baseGui.Close()
}
+// a GO GUI plugin should initTree in init()
+// this should be done before the application
+// starts trying to open up a channel
+func init() {
+ me.myTree = initTree()
+
+}
+
// sets defaults and establishes communication
// to this toolkit from the wit/gui golang package
func initPlugin() {
defer func() {
if r := recover(); r != nil {
- fmt.Fprintf(outf, "PANIC: initPlugin() recovered %v\n", r)
+ fmt.Fprintf(me.outf, "PANIC: initPlugin() recovered %v\n", r)
return
}
}()
var err error
+
+ // read in defaults from config protobuf
+ if val, err := me.myTree.ConfigFind("stdout"); err == nil {
+ if val == "true" {
+ me.stdout.startOnscreen = true
+ // me.stdout.Write([]byte("starting with stdout onscreen\n"))
+ }
+ if val == "disable" {
+ log.Info("COMPLETELY DISABLE LOG CRAP")
+ me.stdout.disable = true
+ }
+ }
+ if val, err := me.myTree.ConfigFind("dark"); err == nil {
+ if val == "true" {
+ me.dark = true
+ }
+ } else {
+ // macos iterm2 really only works with dark mode right now
+ if runtime.GOOS == "macos" {
+ me.dark = true
+ }
+ }
// todo: make this a tmp file that goes away
- outf, err = os.OpenFile("/tmp/captureMode.log", os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666)
- if err != nil {
- log.Info("error opening file:", err)
- os.Exit(0)
+ if !me.stdout.disable {
+ log.Info("USING STDOUT")
+ me.outf, err = os.OpenFile("/tmp/captureMode.log", os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666)
+ if err != nil {
+ log.Info("error opening file:", err)
+ os.Exit(0)
+ }
}
me.starttime = time.Now()
log.Log(INFO, "Init() of awesome-gocui")
@@ -150,41 +183,22 @@ func initPlugin() {
me.mouse.clicktime = time.Millisecond * 200
me.mouse.doubletime = time.Millisecond * 400
- me.myTree = initTree()
-
me.newWindowTrigger = make(chan *guiWidget, 1)
go newWindowTrigger()
go refreshGocui()
- // read in defaults from config protobuf
- if val, err := me.myTree.ConfigFind("stdout"); err == nil {
- if val == "true" {
- me.stdout.startOnscreen = true
- // me.stdout.Write([]byte("starting with stdout onscreen\n"))
- } else {
- // me.stdout.Write([]byte("starting with stdout offscreen\n"))
- }
- }
- if val, err := me.myTree.ConfigFind("dark"); err == nil {
- if val == "true" {
- me.dark = true
- }
+ log.Log(NOW, "Init() start pluginChan")
+ if me.stdout.disable {
+ log.Info("USING STDOUT")
} else {
- // macos iterm2 really only works with dark mode right now
- if runtime.GOOS == "macos" {
- me.dark = true
- }
+ os.Stdout = me.outf
+ log.CaptureMode(me.outf)
}
- log.Log(NOW, "Init() start pluginChan")
-
- os.Stdout = outf
-
- log.CaptureMode(outf)
-
// init gocui
g, err := gocui.NewGui(gocui.OutputNormal, true)
if err != nil {
+ os.Exit(-1)
return
}
me.baseGui = g
@@ -203,7 +217,9 @@ func initPlugin() {
time.Sleep(100 * time.Millisecond)
- fmt.Fprintln(outf, "hello world", time.Since(me.starttime))
+ if me.outf != nil {
+ fmt.Fprintln(me.outf, "hello world", time.Since(me.starttime))
+ }
// coreStdout()
// createStdout(g)
@@ -219,12 +235,18 @@ func gocuiMain() {
defer func() {
if r := recover(); r != nil {
log.Warn("PANIC ecovered in gocuiMain()", r)
- fmt.Fprintf(outf, "PANIC recovered in r = %v", r)
- os.Stderr = outf
- os.Stdout = outf
- debug.PrintStack()
- pprof.Lookup("goroutine").WriteTo(outf, 1)
- panic(outf)
+ if me.outf == nil {
+ debug.PrintStack()
+ pprof.Lookup("goroutine").WriteTo(os.Stdout, 1)
+ panic(os.Stdout)
+ } else {
+ fmt.Fprintf(me.outf, "PANIC recovered in r = %v", r)
+ os.Stderr = me.outf
+ os.Stdout = me.outf
+ debug.PrintStack()
+ pprof.Lookup("goroutine").WriteTo(me.outf, 1)
+ panic(me.outf)
+ }
}
}()
@@ -239,8 +261,10 @@ func gocuiMain() {
func standardExit() {
log.Log(NOW, "standardExit() doing baseGui.Close()")
me.baseGui.Close()
- log.Log(NOW, "standardExit() doing outf.Close()")
- outf.Close()
+ if me.outf != nil {
+ log.Log(NOW, "standardExit() doing outf.Close()")
+ me.outf.Close()
+ }
// log(true, "standardExit() setOutput(os.Stdout)")
// setOutput(os.Stdout)
log.Log(NOW, "standardExit() send back Quit()")
@@ -255,7 +279,7 @@ func standardClose() {
log.Log(NOW, "standardExit() doing baseGui.Close()")
me.baseGui.Close()
log.Log(NOW, "standardExit() doing outf.Close()")
- outf.Close()
+ me.outf.Close()
// os.Stdin = os.Stdin
// os.Stdout = os.Stdout
// os.Stderr = os.Stderr
@@ -297,7 +321,11 @@ func testRefresh(*gocui.Gui) error {
func refreshGocui() {
defer func() {
if r := recover(); r != nil {
- fmt.Fprintln(outf, "INIT PLUGIN recovered in r", r)
+ if me.outf == nil {
+ log.Info("INIT PLUGIN recovered in r", r)
+ } else {
+ fmt.Fprintln(me.outf, "INIT PLUGIN recovered in r", r)
+ }
return
}
}()