diff options
| author | Paul Buetow <paul@buetow.org> | 2024-08-03 14:11:18 +0300 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2024-08-03 14:11:18 +0300 |
| commit | 911bac5345502d099e93aa72a79b91e9ba14f01f (patch) | |
| tree | 0edf4a7de7cb9d6901c690342447d7483646bd4a /internal | |
| parent | 5664c4ad14fca54a42356541847e6ae3f9613a87 (diff) | |
adding Cmd to all functions returning a tea.Cmd
Diffstat (limited to 'internal')
| -rw-r--r-- | internal/client/tui/compose.go | 8 | ||||
| -rw-r--r-- | internal/client/tui/submit.go | 10 | ||||
| -rw-r--r-- | internal/client/tui/tui.go | 12 |
3 files changed, 15 insertions, 15 deletions
diff --git a/internal/client/tui/compose.go b/internal/client/tui/compose.go index c2d5c16..61883f8 100644 --- a/internal/client/tui/compose.go +++ b/internal/client/tui/compose.go @@ -20,19 +20,19 @@ const ( submitAfterCompose ) -func composeAction(ctx context.Context, conf config.ClientConfig, postAction composePostAction) tea.Cmd { +func composeActionCmd(ctx context.Context, conf config.ClientConfig, postAction composePostAction) tea.Cmd { err := ensureDirectoryExists(conf.DataDir) composeFile := fmt.Sprintf("%s/%s", conf.DataDir, conf.ComposeFile) log.Println("Composing", composeFile) - return openEditor(conf.Editor, composeFile, func() error { + return openEditorCmd(conf.Editor, composeFile, func() error { if err != nil { return err } switch postAction { case submitAfterCompose: - return submitEntryNoCmd(ctx, conf, composeFile) + return submitEntry(ctx, conf, composeFile) case queueAfterCompose: timestamp := time.Now().Format("20060102-150405") queuedFile := fmt.Sprintf("%s/queued-%s.txt", conf.DataDir, timestamp) @@ -43,7 +43,7 @@ func composeAction(ctx context.Context, conf config.ClientConfig, postAction com }) } -func openEditor(editor, filePath string, cb func() error) tea.Cmd { +func openEditorCmd(editor, filePath string, cb func() error) tea.Cmd { return tea.ExecProcess(exec.Command(editor, filePath), func(err error) tea.Msg { return finishedMsg{ cb: cb, diff --git a/internal/client/tui/submit.go b/internal/client/tui/submit.go index 3ab4ab5..d0b4c78 100644 --- a/internal/client/tui/submit.go +++ b/internal/client/tui/submit.go @@ -14,22 +14,22 @@ import ( tea "github.com/charmbracelet/bubbletea" ) -func submitAction(ctx context.Context, conf config.ClientConfig) tea.Cmd { +func submitActionCmd(ctx context.Context, conf config.ClientConfig) tea.Cmd { composeFile := fmt.Sprintf("%s/%s", conf.DataDir, conf.ComposeFile) log.Println("Submitting", composeFile) - return submitEntry(ctx, conf, composeFile, func() error { + return submitEntryCmd(ctx, conf, composeFile, func() error { // This is the cb to call when the entry was submitted succesfully return nil }) } -func submitEntry(ctx context.Context, conf client.ClientConfig, composeFile string, cb func() error) tea.Cmd { - return finished(cb, submitEntryNoCmd(ctx, conf, composeFile)) +func submitEntryCmd(ctx context.Context, conf client.ClientConfig, composeFile string, cb func() error) tea.Cmd { + return finished(cb, submitEntry(ctx, conf, composeFile)) } // TODO: Rename all functions returning a Cmd so that they have a Cmd suffix -func submitEntryNoCmd(ctx context.Context, conf client.ClientConfig, composeFile string) error { +func submitEntry(ctx context.Context, conf client.ClientConfig, composeFile string) error { servers, err := conf.Servers() if err != nil { return err diff --git a/internal/client/tui/tui.go b/internal/client/tui/tui.go index 2ca2c10..c084d9c 100644 --- a/internal/client/tui/tui.go +++ b/internal/client/tui/tui.go @@ -76,18 +76,18 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { case "enter": switch m.cursor { case cursorCompose: - return m, composeAction(m.ctx, m.conf, noPostAction) + return m, composeActionCmd(m.ctx, m.conf, noPostAction) case cursorSubmit: - return m, submitAction(m.ctx, m.conf) + return m, submitActionCmd(m.ctx, m.conf) case cursorComposeAndSubmit: - return m, composeAction(m.ctx, m.conf, submitAfterCompose) + return m, composeActionCmd(m.ctx, m.conf, submitAfterCompose) } case "1": - return m, composeAction(m.ctx, m.conf, noPostAction) + return m, composeActionCmd(m.ctx, m.conf, noPostAction) case "2": - return m, submitAction(m.ctx, m.conf) + return m, submitActionCmd(m.ctx, m.conf) case "3": - return m, composeAction(m.ctx, m.conf, submitAfterCompose) + return m, composeActionCmd(m.ctx, m.conf, submitAfterCompose) case "a": m.altscreenActive = !m.altscreenActive |
