From 1e450d4e34006b82dff4998a7a5380726f63c66d Mon Sep 17 00:00:00 2001 From: Ayman Bagabas Date: Mon, 14 Nov 2022 18:54:03 -0500 Subject: [PATCH] chore(mouse): update mouse example --- examples/mouse/main.go | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/examples/mouse/main.go b/examples/mouse/main.go index ea5c11d40a..6bf8fd7ba7 100644 --- a/examples/mouse/main.go +++ b/examples/mouse/main.go @@ -4,21 +4,19 @@ package main // coordinates and events. import ( - "fmt" "log" tea "github.com/charmbracelet/bubbletea" ) func main() { - p := tea.NewProgram(model{}, tea.WithAltScreen(), tea.WithMouseAllMotion()) + p := tea.NewProgram(model{}, tea.WithMouseAllMotion(), tea.WithMouseExtendedMode()) if _, err := p.Run(); err != nil { log.Fatal(err) } } type model struct { - init bool mouseEvent tea.MouseEvent } @@ -34,20 +32,14 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { } case tea.MouseMsg: - m.init = true - m.mouseEvent = tea.MouseEvent(msg) + return m, tea.Printf("(X: %d, Y: %d) %s", msg.X, msg.Y, tea.MouseEvent(msg)) } return m, nil } func (m model) View() string { - s := "Do mouse stuff. When you're done press q to quit.\n\n" - - if m.init { - e := m.mouseEvent - s += fmt.Sprintf("(X: %d, Y: %d) %s", e.X, e.Y, e) - } + s := "Do mouse stuff. When you're done press q to quit.\n" return s }