Add ProgramOptions for entering the altscreen and enabling the mouse

Because they run ansyncronously, the analogous commands, when run in
a Model's Init() function, could fire after the renderer has starting
writing to output, rendering artifacts to the commandline.
This commit is contained in:
Christian Rocha
2021-05-19 20:52:01 -04:00
parent ec2fbf024b
commit 85ab476698
4 changed files with 176 additions and 60 deletions

View File

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