From ecc323b3b45e666a3376d7983424837d58336198 Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Mon, 1 Jul 2024 10:50:23 +0300 Subject: initial submit --- internal/client/tui/compose.go | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) (limited to 'internal/client/tui/compose.go') diff --git a/internal/client/tui/compose.go b/internal/client/tui/compose.go index 7bdfbf3..3ba53ec 100644 --- a/internal/client/tui/compose.go +++ b/internal/client/tui/compose.go @@ -6,30 +6,33 @@ import ( "os/exec" "time" + config "codeberg.org/snonux/gos/internal/config/client" tea "github.com/charmbracelet/bubbletea" ) -type composeFinishedMsg struct { - callback func() error - err error -} - -func composeAction(editor, dataDir string) tea.Cmd { - // Maybe handle the error explicitly? Should be obvious anyway - // when the editor can't open the file because directory isn't there - _ = ensureDirectoryExists(dataDir) - composeFile := fmt.Sprintf("%s/compose.txt", dataDir) +func composeAction(conf config.ClientConfig, queue bool) tea.Cmd { + err := ensureDirectoryExists(conf.DataDir) + composeFile := fmt.Sprintf("%s/%s", conf.DataDir, conf.ComposeFile) - return openEditor(editor, composeFile, func() error { + return openEditor(conf.Editor, composeFile, func() error { + if err != nil { + return err + } + if !queue { + return nil + } timestamp := time.Now().Format("20060102-150405") - queuedFile := fmt.Sprintf("%s/queued-%s.txt", dataDir, timestamp) + queuedFile := fmt.Sprintf("%s/queued-%s.txt", conf.DataDir, timestamp) return os.Rename(composeFile, queuedFile) }) } func openEditor(editor, filePath string, callback func() error) tea.Cmd { return tea.ExecProcess(exec.Command(editor, filePath), func(err error) tea.Msg { - return composeFinishedMsg{callback, err} + return finishedMsg{ + callback: callback, + err: err, + } }) } -- cgit v1.2.3