diff options
| -rw-r--r-- | args.go | 2 | ||||
| -rw-r--r-- | main.go | 55 | ||||
| -rw-r--r-- | plugin.go | 2 |
3 files changed, 58 insertions, 1 deletions
@@ -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 @@ -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() +} @@ -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 |
