Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improvements: Races and Rendering #107

Merged
merged 3 commits into from
Jun 2, 2021
Merged

Improvements: Races and Rendering #107

merged 3 commits into from
Jun 2, 2021

Conversation

meowgorithm
Copy link
Member

@meowgorithm meowgorithm commented Jun 2, 2021

This release introduces three new ProgramOptions 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.


New

  • Added ProgramOption WithAltScreen for starting programs in the alternate screen buffer.
  • Added ProgramOptions WithMouseCellMotion and WithMouseAllMotion 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.

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 also consolidates the exit operations for consistency's
sake, and adds a kill() method to renderers for stopping them without
performing any final rendering.
@meowgorithm meowgorithm merged commit 6547773 into master Jun 2, 2021
@meowgorithm meowgorithm deleted the races-and-a-bug branch June 2, 2021 18:49
@meowgorithm meowgorithm changed the title Bugfixes: Races and Rendering Improvements: Races and Rendering Jun 2, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant