diff --git a/internal/cmd/extension.go b/internal/cmd/extension.go index 14842c64..60c55bb4 100644 --- a/internal/cmd/extension.go +++ b/internal/cmd/extension.go @@ -26,7 +26,8 @@ func extensionCmd() *cobra.Command { tui.MinimalKeyMap, tui.DefaultStyles, ) - return newProgram(cmd, model).Start() + _, err := newProgram(cmd, model).Start() + return err }, } diff --git a/internal/cmd/suggest.go b/internal/cmd/suggest.go index 276ccd0d..ab6d5160 100644 --- a/internal/cmd/suggest.go +++ b/internal/cmd/suggest.go @@ -79,10 +79,13 @@ or just bad. Please use with discretion. } model := tui.NewListModel(ctx, description, repoUser, client) - err = newProgram(cmd, model).Start() + m, err := newProgram(cmd, model).Start() + if err != nil { + return err + } - if err == nil { - _, err = fmt.Fprintln(cmd.OutOrStdout(), "Great choice! Learn how to run your dev workflows with https://runme.dev/") + if mm, ok := m.(tui.ListModel); ok && mm.Confirmed() { + _, err = fmt.Fprintf(cmd.OutOrStdout(), "Great choice! Learn how to run your markdown files with https://runme.dev/\n\n") } return err diff --git a/internal/cmd/tui_common.go b/internal/cmd/tui_common.go index 36dd04f9..bc7226d2 100644 --- a/internal/cmd/tui_common.go +++ b/internal/cmd/tui_common.go @@ -13,12 +13,12 @@ type program struct { out io.Writer } -func (p *program) Start() error { +func (p *program) Start() (tea.Model, error) { if f, ok := p.out.(*os.File); ok && !isTerminal(f.Fd()) { go p.Quit() } - _, err := p.Program.Run() - return err + m, err := p.Program.Run() + return m, err } func newProgramWithOutputs(output io.Writer, input io.Reader, model tea.Model, opts ...tea.ProgramOption) *program { diff --git a/internal/tui/model_list.go b/internal/tui/model_list.go index bd821a9e..33c0a1a9 100644 --- a/internal/tui/model_list.go +++ b/internal/tui/model_list.go @@ -93,6 +93,7 @@ func NewListModel(ctx context.Context, description string, repoUser string, clie editInput: ti, editHelp: help.New(), spinner: s, + confirmed: false, loading: true, usePrefix: true, } @@ -107,6 +108,10 @@ func NewListModel(ctx context.Context, description string, repoUser string, clie return m } +func (m ListModel) Confirmed() bool { + return m.confirmed +} + func (m ListModel) startSearch() tea.Msg { userBranches, err := project.GetUsersBranches(m.repoUser) if err != nil { @@ -296,12 +301,12 @@ func (m ListModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) { case confirmMsg: m.confirmed = true fmt.Printf("Output: %s", msg.response) - return m, tea.Quit // see https://github.com/charmbracelet/bubbletea/discussions/273 + return m, tea.Quit case errorMsg: m.loading = false m.err = msg.Err - return m, nil // see https://github.com/charmbracelet/bubbletea/discussions/273 // tea.Quit + return m, tea.Quit // now fixed https://github.com/charmbracelet/bubbletea/issues/274 } m.list, cmd = m.list.Update(msg)