Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion tutorials/basics/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package main
import (
"fmt"
"os"
"strings"

tea "charm.land/bubbletea/v2"
)
Expand Down Expand Up @@ -57,6 +58,7 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
}

func (m model) View() tea.View {
var sb strings.Builder
s := "What should we buy at the market?\n\n"

for i, choice := range m.choices {
Expand All @@ -70,9 +72,10 @@ func (m model) View() tea.View {
checked = "x"
}

s += fmt.Sprintf("%s [%s] %s\n", cursor, checked, choice)
fmt.Fprintf(&sb, "%s [%s] %s\n", cursor, checked, choice)
}

s += sb.String()
s += "\nPress q to quit.\n"

v := tea.NewView(s)
Expand Down