Skip to content
Myr

Update mouse example to use new Model interface-based structure

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Christian Rocha · committed by Christian Rocha · parent 7507f3d · Browse files · 1 file+5 added−9 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+5 added−9 removed

  • other:+5 added−9 removed

1 file+5 added−9 removed

modified:examples/mouse/main.go+5 added-9 removed
9 unmodified lines
10 tea "github.com/charmbracelet/bubbletea"11)1213func main() {14 p := tea.NewProgram(initialize, update, view)14 p := tea.NewProgram(model{})1516 p.EnterAltScreen()17 defer p.ExitAltScreen()18 p.EnableMouseAllMotion()
8 unmodified lines
27 init bool28 mouseEvent tea.MouseEvent29}3031func initialize() (tea.Model, tea.Cmd) {32 return model{}, nil31func (m model) Init() tea.Cmd {32 return nil33}3435func update(msg tea.Msg, mdl tea.Model) (tea.Model, tea.Cmd) {36 m, _ := mdl.(model)3735func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {36 switch msg := msg.(type) {37 case tea.KeyMsg:38 if msg.Type == tea.KeyCtrlC || (msg.Type == tea.KeyRune && msg.Rune == 'q') {39 return m, tea.Quit
6 unmodified lines
4647 return m, nil48}4952func view(mdl tea.Model) string {53 m, _ := mdl.(model)5450func (m model) View() string {51 s := "Do mouse stuff. When you're done press q to quit.\n\n"5253 if m.init {54 e := m.mouseEvent
5 unmodified lines