Add cmds for toggling mouse mode + deprecate equivalent Program methods

Also automatically disable mouse mode on exit.
This commit is contained in:
Christian Rocha
2021-05-03 14:27:20 -04:00
parent 7c0bbc7d32
commit 5c150ebf38
2 changed files with 67 additions and 19 deletions

View File

@@ -11,14 +11,7 @@ import (
)
func main() {
p := tea.NewProgram(model{})
p.EnterAltScreen()
defer p.ExitAltScreen()
p.EnableMouseAllMotion()
defer p.DisableMouseAllMotion()
if err := p.Start(); err != nil {
if err := tea.NewProgram(model{}).Start(); err != nil {
log.Fatal(err)
}
}
@@ -29,7 +22,7 @@ type model struct {
}
func (m model) Init() tea.Cmd {
return nil
return tea.Batch(tea.EnterAltScreen, tea.EnableMouseAllMotion)
}
func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {