Fix a race where artifacts could print when exiting a program

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.
This commit is contained in:
Christian Rocha
2021-05-19 21:35:36 -04:00
parent 85ab476698
commit 1f773e8f20
4 changed files with 46 additions and 16 deletions

View File

@@ -61,13 +61,19 @@ func (r *standardRenderer) start() {
go r.listen()
}
// stop permanently halts the renderer.
// stop permanently halts the renderer, rendering the final frame.
func (r *standardRenderer) stop() {
r.flush()
clearLine(r.out)
close(r.done)
}
// kill halts the renderer. The final frame will not be rendered.
func (r *standardRenderer) kill() {
clearLine(r.out)
close(r.done)
}
// listen waits for ticks on the ticker, or a signal to stop the renderer.
func (r *standardRenderer) listen() {
for {