Skip to content

Commit

Permalink
fix(examples): Fix bugs in package-manager
Browse files Browse the repository at this point in the history
  • Loading branch information
AkshayKalose authored and meowgorithm committed Jun 28, 2024
1 parent 60a57ea commit 4a9620e
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions examples/package-manager/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()
Expand Down

0 comments on commit 4a9620e

Please sign in to comment.