From 4523eda0fa2372d97fb5db800b79b53c218ef627 Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Mon, 17 Mar 2025 05:35:57 -0500 Subject: [PATCH] remove the tmp file --- init.go | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/init.go b/init.go index 87cec5a..b13f634 100644 --- a/init.go +++ b/init.go @@ -157,12 +157,15 @@ func initPlugin() { } // todo: make this a tmp file that goes away if !me.stdout.disable { - log.Log(INFO, "stdout.disable == true. writing to /tmp/captureMode.log") - me.outf, err = os.OpenFile("/tmp/captureMode.log", os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666) + tmpFile, err := os.CreateTemp("", "gocui-*.log") if err != nil { - log.Info("error opening file:", err) - os.Exit(0) + fmt.Println("Error creating temp file:", err) + standardExit() } + // defer os.Remove(tmpFile.Name()) + + log.Log(INFO, "stdout.disable == true. writing to", tmpFile.Name()) + me.outf = tmpFile // todo: some early output still goes to the /tmp/ file //time.Sleep(200 * time.Millisecond) log.CaptureMode(me.stdout) @@ -289,6 +292,7 @@ func standardExit() { if me.outf != nil { log.Log(NOW, "standardExit() doing outf.Close()") me.outf.Close() + os.Remove(me.outf.Name()) } // log(true, "standardExit() setOutput(os.Stdout)") // setOutput(os.Stdout) @@ -305,6 +309,7 @@ func standardClose() { me.baseGui.Close() log.Log(NOW, "standardExit() doing outf.Close()") me.outf.Close() + os.Remove(me.outf.Name()) // os.Stdin = os.Stdin // os.Stdout = os.Stdout // os.Stderr = os.Stderr