package main import ( "fmt" "os" tea "charm.land/bubbletea/v2" ) type model struct { name string sayHello bool } func initialModel() model { return model{ name: "jason", sayHello: false, } } func (m model) Init() tea.Cmd { // any init commands like fetching data etc // to populate model if need be return nil } // Update loop like a game func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { switch msg := msg.(type) { // Handle key presses case tea.KeyMsg: switch msg.String() { // Quit the app case "ctrl+c", "q": return m, tea.Quit // Toggle the greeting case "enter", " ": m.sayHello = !m.sayHello } } return m, nil } // View: Returns a string representing the UI. like a render method func (m model) View() tea.View { s := "nfeeder Dev Console\n" s += "-------------------\n\n" if m.sayHello { s += fmt.Sprintf("Hello, %s! Nice to see you.\n\n", m.name) } else { s += "Press ENTER to say hello.\n\n" } s += "Press 'q' to quit.\n" return tea.NewView(s) } func main() { p := tea.NewProgram(initialModel()) if _, err := p.Run(); err != nil { fmt.Printf("Alas, there's been an error: %v", err) os.Exit(1) } }