summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeff Carr <[email protected]>2024-02-12 15:15:42 -0600
committerJeff Carr <[email protected]>2024-02-12 15:15:42 -0600
commit54dcbee6f11af4f8d746dfe85405683984fa2fa4 (patch)
treeb7f5ea2638a8ce8b5867cf487a4ab02974af6af2
parentc7ea23ddb6559030d0be98bff090bf919b0c4265 (diff)
add 'dead' to track plugin failure
-rw-r--r--args.go2
-rw-r--r--main.go55
-rw-r--r--plugin.go2
3 files changed, 58 insertions, 1 deletions
diff --git a/args.go b/args.go
index 62e75f2..c63905e 100644
--- a/args.go
+++ b/args.go
@@ -10,6 +10,8 @@ var argGui ArgsGui
type ArgsGui struct {
GuiPlugin string `arg:"--gui" help:"Use this gui toolkit [andlabs,gocui,nocui]"`
GuiVerbose bool `arg:"--gui-verbose" help:"enable all logging"`
+ // this doesn't work, maybe it can't work
+ // GuiStdout bool `arg:"--gui-stdout" help:"send STDOUT and STDERR to /tmp/go-gui.log"`
}
// returns the toolkit
diff --git a/main.go b/main.go
index df716e3..bceed9e 100644
--- a/main.go
+++ b/main.go
@@ -1,6 +1,7 @@
package gui
import (
+ "fmt"
"os"
"go.wit.com/log"
@@ -185,6 +186,13 @@ func (n *Node) gotUserEvent(a widget.Action) {
// some toolkit's on some operating systems don't support more than one
// Keep things simple. Do the default expected thing whenever possible
func New() *Node {
+ /*
+ if argGui.GuiStdout {
+ log.Log(WARN, "--gui-stdout doesn't work yet")
+ // trapStdout()
+ }
+ */
+
return me.rootNode
}
@@ -236,3 +244,50 @@ func (n *Node) StandardExit() {
}
log.Exit(0)
}
+
+var origStdout *os.File
+var origStderr *os.File
+var guioutf *os.File
+var guierrf *os.File
+
+// THIS DOES NOT WORK.
+// this needs to work like screen. somehow make pseudo tty's or something
+// to correctly isolate and trap STDOUT and STDERR so the gocui can work
+func trapStdout() {
+ // attempts to control STDOUT
+ var err error
+ log.Log(WARN, "trapStdout() START")
+
+ guioutf, err = os.OpenFile("/tmp/go-gui.log", os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666)
+ if err != nil {
+ log.Error(err, "error opening /tmp/go-gui.log")
+ os.Exit(0)
+ }
+ origStdout = os.Stdout
+ os.Stdout = guioutf
+ // defer guioutf.Close()
+
+ // setOutput(outf)
+ // log("This is a test log entry")
+
+ guierrf, err = os.OpenFile("/tmp/go-gui.err", os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0664)
+ if err != nil {
+ log.Error(err, "error opening /tmp/go-gui.err")
+ os.Exit(0)
+ }
+ // defer guierrf.Close()
+ origStderr = os.Stderr
+ os.Stderr = guierrf
+
+ println("TEST println")
+ println("TEST println")
+ println("TEST println")
+ fmt.Println("TEST fmt")
+ fmt.Println("TEST fmt")
+ fmt.Println("TEST fmt")
+ log.Info("TEST log")
+ log.Info("TEST log")
+ log.Info("TEST log")
+
+ // defer guioutf.Close()
+}
diff --git a/plugin.go b/plugin.go
index 2f72c50..191c4ee 100644
--- a/plugin.go
+++ b/plugin.go
@@ -26,7 +26,7 @@ type aplug struct {
// set this to true if the plugin dies
// TODO: remove the plugin from the pool
- dead bool
+ dead bool
// this tells the toolkit plugin how to send events
// back here