Signed-off-by: Hadi <112569860+anotherhadi@users.noreply.github.com>
This commit is contained in:
Hadi
2026-05-26 19:59:34 +02:00
commit f3dce1f4ab
29 changed files with 2218 additions and 0 deletions
+47
View File
@@ -0,0 +1,47 @@
package util
import (
"os"
"os/exec"
tea "charm.land/bubbletea/v2"
)
type EditorFinishedMsg struct {
Content string
Err error
}
func OpenExternalEditor(content string) tea.Cmd {
editor := os.Getenv("EDITOR")
if editor == "" {
editor = os.Getenv("VISUAL")
}
if editor == "" {
editor = "vi"
}
f, err := os.CreateTemp("", "jwt-tui-*.json")
if err != nil {
return func() tea.Msg { return EditorFinishedMsg{Err: err} }
}
tmpPath := f.Name()
if _, werr := f.WriteString(content); werr != nil {
f.Close()
os.Remove(tmpPath)
return func() tea.Msg { return EditorFinishedMsg{Err: werr} }
}
f.Close()
return tea.ExecProcess(exec.Command(editor, tmpPath), func(err error) tea.Msg {
defer os.Remove(tmpPath)
if err != nil {
return EditorFinishedMsg{Err: err}
}
data, readErr := os.ReadFile(tmpPath)
if readErr != nil {
return EditorFinishedMsg{Err: readErr}
}
return EditorFinishedMsg{Content: string(data)}
})
}