summaryrefslogtreecommitdiff
path: root/doEditor.go
diff options
context:
space:
mode:
authorJeff Carr <[email protected]>2025-08-30 15:15:43 -0500
committerJeff Carr <[email protected]>2025-08-30 15:15:43 -0500
commitc7896e47f9c91e330b023bdb34a7540f193a5422 (patch)
tree76a0801d34c7b53442e2e5d2ecaeba5ef5e961c0 /doEditor.go
parent7f8f5e3b9b37fccbb357b70e6490823a8b22ae7e (diff)
code cleanup of early drafts of code from Gemini AI
Diffstat (limited to 'doEditor.go')
-rw-r--r--doEditor.go92
1 files changed, 0 insertions, 92 deletions
diff --git a/doEditor.go b/doEditor.go
deleted file mode 100644
index acaf75c..0000000
--- a/doEditor.go
+++ /dev/null
@@ -1,92 +0,0 @@
-package main
-
-import (
- "io/ioutil"
- "os"
- "os/exec"
- "strings"
- "time"
-
- "go.wit.com/log"
-)
-
-func doEditor() error {
- for {
- filename, err := doEditorOnce()
- if err != nil {
- return err
- }
- log.Info("filename:", filename)
-
- for {
- _, err := os.Stat("/tmp/regex.ready")
- if err == nil {
- break
- }
- time.Sleep(100 * time.Millisecond)
- }
- // read in regex.ready exists (should be SessionID)
- // Println session ID
- content, err := ioutil.ReadFile("/tmp/regex.ready")
- if err != nil {
- log.Error(err)
- }
- os.Remove("/tmp/regex.ready")
- log.Info("SessionID: %s", string(content))
-
- logContent, err := ioutil.ReadFile("/tmp/regex.log")
- if err != nil {
- log.Errorf("could not read regex.log: %v", err)
- } else {
- log.Info("contents of /tmp/regex.log:")
- os.Stdout.Write(logContent)
- }
-
- time.Sleep(5 * time.Second)
- }
-}
-
-func doEditorOnce() (string, error) {
- // Create a temporary file
- tmpfile, err := ioutil.TempFile("", "regex-*.txt")
- if err != nil {
- return "", err
- }
- tmpPath := tmpfile.Name()
- // Defer removal in case of error, but we might move it
- defer os.Remove(tmpPath)
- tmpfile.Close()
-
- // Get the user's editor
- editor := os.Getenv("EDITOR")
- if editor == "" {
- editor = "vim" // default to vim
- }
-
- // Run the editor
- cmd := exec.Command(editor, tmpPath)
- cmd.Stdin = os.Stdin
- cmd.Stdout = os.Stdout
- cmd.Stderr = os.Stderr
-
- if err := cmd.Run(); err != nil {
- return "", err
- }
-
- // Read the file content
- content, err := ioutil.ReadFile(tmpPath)
- if err != nil {
- return "", err
- }
-
- // Check if the file is not empty after trimming space
- if strings.TrimSpace(string(content)) != "" {
- // Move the file
- if err := os.Rename(tmpPath, "/tmp/regex.txt"); err != nil {
- return "", err
- }
- return "/tmp/regex.txt", nil
- }
-
- return "", nil
-}