mirror of
https://github.com/taigrr/bubbletea.git
synced 2026-04-16 18:15:03 -07:00
Tidy up tutorials
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user