-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.go
More file actions
41 lines (32 loc) · 923 Bytes
/
main.go
File metadata and controls
41 lines (32 loc) · 923 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package main
import (
"fmt"
"os"
tea "github.com/charmbracelet/bubbletea"
"github.com/iptch/go-techbier/pokeapi"
"github.com/iptch/go-techbier/ui"
)
func main() {
model := ui.InitialModel()
program := tea.NewProgram(model, tea.WithAltScreen())
go DownloadPokemon(program)
if _, err := program.Run(); err != nil {
fmt.Println("Error running program:", err)
os.Exit(1)
}
}
// DownloadPokemon will call GetAllPokemon to retrieve Pokémon from the PokéAPI.
// Once the download has completed it sends a downloadCompleted message to the
// bubbles Program.
func DownloadPokemon(p *tea.Program) {
c := make(chan []pokeapi.PokeapiRef[pokeapi.Pokemon])
go pokeapi.GetAllPokemon(c)
// create list from Pokémon items
for pokemonRefs := range c {
for _, pokemonRef := range pokemonRefs {
pokemonRef := pokemonRef
p.Send(ui.NewPokemon{Pokemon: pokemonRef})
}
}
p.Send(ui.DownloadCompleted{})
}