From a1407cd9c960da7cb7e13b37ec444590319b8908 Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Mon, 22 Jun 2026 14:25:14 +0300 Subject: Fix description editor ExecProcess flow for nq0 --- internal/ui/table.go | 39 +++++++++++++++++++++++---------------- 1 file changed, 23 insertions(+), 16 deletions(-) (limited to 'internal/ui/table.go') diff --git a/internal/ui/table.go b/internal/ui/table.go index e629c20..59eaaeb 100644 --- a/internal/ui/table.go +++ b/internal/ui/table.go @@ -237,6 +237,10 @@ type descEditDoneMsg struct { tempFile string } +type descEditLaunchMsg struct { + tempFile string +} + type shellDoneMsg struct { result task.RunResult err error @@ -320,7 +324,7 @@ func editCmd(id int) tea.Cmd { return tea.ExecProcess(c, func(err error) tea.Msg { return editDoneMsg{err: err} }) } -// editDescriptionCmd returns a command that opens the description in external editor +// editDescriptionCmd returns a command that prepares the description temp file. func editDescriptionCmd(description string) tea.Cmd { return func() tea.Msg { tmpPath, err := prepareDescriptionTempFile(description, func() (descriptionTempFile, error) { @@ -330,23 +334,24 @@ func editDescriptionCmd(description string) tea.Cmd { return descEditDoneMsg{err: err, tempFile: ""} } - // Get editor from environment - editor := os.Getenv("EDITOR") - if editor == "" { - editor = "vi" // fallback to vi - } - - // Create the command - c := exec.Command(editor, tmpPath) - c.Stdin = os.Stdin - c.Stdout = os.Stdout - c.Stderr = os.Stderr + return descEditLaunchMsg{tempFile: tmpPath} + } +} - // Use ExecProcess to properly handle the external TUI editor - return tea.ExecProcess(c, func(err error) tea.Msg { - return descEditDoneMsg{err: err, tempFile: tmpPath} - })() +func launchDescriptionEditorCmd(tmpPath string) tea.Cmd { + editor := os.Getenv("EDITOR") + if editor == "" { + editor = "vi" } + + c := exec.Command(editor, tmpPath) + c.Stdin = os.Stdin + c.Stdout = os.Stdout + c.Stderr = os.Stderr + + return tea.ExecProcess(c, func(err error) tea.Msg { + return descEditDoneMsg{err: err, tempFile: tmpPath} + }) } func blinkCmd() tea.Cmd { @@ -608,6 +613,8 @@ func (m *Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { return m.handleWindowResize(msg) case editDoneMsg: return m.handleEditDone(msg) + case descEditLaunchMsg: + return m, launchDescriptionEditorCmd(msg.tempFile) case descEditDoneMsg: return m.handleDescEditDone(msg) case shellDoneMsg: -- cgit v1.2.3