summaryrefslogtreecommitdiffstats
path: root/ui/editor.go
diff options
context:
space:
mode:
Diffstat (limited to 'ui/editor.go')
-rw-r--r--ui/editor.go33
1 files changed, 33 insertions, 0 deletions
diff --git a/ui/editor.go b/ui/editor.go
new file mode 100644
index 0000000..60cc320
--- /dev/null
+++ b/ui/editor.go
@@ -0,0 +1,33 @@
+package ui
+
+import (
+ "os"
+ "os/exec"
+ "strings"
+
+ tea "github.com/charmbracelet/bubbletea"
+)
+
+const defaultEditor = "nano"
+
+type editorFinishedMsg struct{ err error }
+
+func openEditor(path string) tea.Cmd {
+ editor, args := getEditor()
+ cmd := exec.Command(editor, append(args, path)...)
+ cb := func(err error) tea.Msg {
+ return editorFinishedMsg{err}
+ }
+ return tea.ExecProcess(cmd, cb)
+}
+
+func getEditor() (string, []string) {
+ editor := strings.Fields(os.Getenv("EDITOR"))
+ if len(editor) > 1 {
+ return editor[0], editor[1:]
+ }
+ if len(editor) == 1 {
+ return editor[0], []string{}
+ }
+ return defaultEditor, []string{}
+}