Improvements: Races and Rendering
This release introduces three new ProgramOption
s for starting programs with the altscreen and mouse enabled. This was implemented to solve both race conditions when initializing programs as well as correctness with regard to custom inputs.
// New! This is the recommended way to start your program with the mouse and altscreen active.
p := tea.NewProgram(model, tea.WithAltScreen(), tea.WithMouseAllMotion())
// Deprecated as this will only operate on stdout, as opposed to a custom output you may have set.
p := tea.NewProgram(model)
p.EnableAltScreen()
p.EnableMouseAllMotion()
// Strongly discouraged as these commands could be sent before starting the renderer, resulting
// in rendering artifacts. This is due to the fact that commands run asynchronously in a goroutine.
func (m model) Init() tea.Cmd {
return tea.Batch(tea.EnterAltScreen, tea.EnableMouseAllMotion)
}
Also included are two subtle—yet important—rendering improvements.
Changelog
New
- Added
ProgramOption
WithAltScreen
for starting programs in the alternate screen buffer. - Added
ProgramOption
sWithMouseCellMotion
andWithMouseAllMotion
for starting programs with the mouse enabled.
Fixed
- Programs will no longer render artifacts when exiting due to an error or panic.
- If a view returns the empty string output will be cleared. Previously, rendering would be skipped entirely.
Thoughts? Questions? We love hearing from you. Feel free to reach out on Twitter, The Fediverse, or right here in GitHub Discussions.