Skip to content

Commit

Permalink
Update closing message (#315)
Browse files Browse the repository at this point in the history
  • Loading branch information
sourishkrout authored Jun 26, 2023
1 parent f5ec767 commit 7b35186
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 9 deletions.
3 changes: 2 additions & 1 deletion internal/cmd/extension.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ func extensionCmd() *cobra.Command {
tui.MinimalKeyMap,
tui.DefaultStyles,
)
return newProgram(cmd, model).Start()
_, err := newProgram(cmd, model).Start()
return err
},
}

Expand Down
9 changes: 6 additions & 3 deletions internal/cmd/suggest.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions internal/cmd/tui_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
9 changes: 7 additions & 2 deletions internal/tui/model_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
Expand All @@ -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 {
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 7b35186

Please sign in to comment.