Tidy up tutorials

This commit is contained in:
Christian Rocha
2021-09-04 14:36:49 -04:00
parent ad19c664fe
commit 9d0e1db101
4 changed files with 108 additions and 110 deletions

View File

@@ -13,6 +13,17 @@ type model struct {
selected map[int]struct{}
}
func initialModel() model {
return model{
choices: []string{"Buy carrots", "Buy celery", "Buy kohlrabi"},
// A map which indicates which choices are selected. We're using
// the map like a mathematical set. The keys refer to the indexes
// of the `choices` slice, above.
selected: make(map[int]struct{}),
}
}
func (m model) Init() tea.Cmd {
return nil
}
@@ -67,12 +78,7 @@ func (m model) View() string {
}
func main() {
initialModel := model{
choices: []string{"Carrots", "Celery", "Kohlrabi"},
selected: make(map[int]struct{}),
}
p := tea.NewProgram(initialModel)
p := tea.NewProgram(initialModel())
if err := p.Start(); err != nil {
fmt.Printf("Alas, there's been an error: %v", err)
os.Exit(1)