diff --git a/examples/package-manager/main.go b/examples/package-manager/main.go index eb6f69ad2d..ca109b6559 100644 --- a/examples/package-manager/main.go +++ b/examples/package-manager/main.go @@ -58,20 +58,24 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { return m, tea.Quit } case installedPkgMsg: + pkg := m.packages[m.index] if m.index >= len(m.packages)-1 { // Everything's been installed. We're done! m.done = true - return m, tea.Quit + return m, tea.Sequence( + tea.Printf("%s %s", checkMark, pkg), // print the last success message + tea.Quit, // exit the program + ) } // Update progress bar - progressCmd := m.progress.SetPercent(float64(m.index) / float64(len(m.packages)-1)) - m.index++ + progressCmd := m.progress.SetPercent(float64(m.index) / float64(len(m.packages))) + return m, tea.Batch( progressCmd, - tea.Printf("%s %s", checkMark, m.packages[m.index]), // print success message above our program - downloadAndInstall(m.packages[m.index]), // download the next package + tea.Printf("%s %s", checkMark, pkg), // print success message above our program + downloadAndInstall(m.packages[m.index]), // download the next package ) case spinner.TickMsg: var cmd tea.Cmd @@ -95,7 +99,7 @@ func (m model) View() string { return doneStyle.Render(fmt.Sprintf("Done! Installed %d packages.\n", n)) } - pkgCount := fmt.Sprintf(" %*d/%*d", w, m.index, w, n-1) + pkgCount := fmt.Sprintf(" %*d/%*d", w, m.index, w, n) spin := m.spinner.View() + " " prog := m.progress.View()