diff --git a/tea.go b/tea.go index 4c6102f858..a1998cd161 100644 --- a/tea.go +++ b/tea.go @@ -517,9 +517,6 @@ type Program struct { // once is used to stop the renderer. once sync.Once - // rendererDone is used to stop the renderer. - rendererDone chan struct{} - // Initial window size. Mainly used for testing. width, height int @@ -577,7 +574,6 @@ func NewProgram(model Model, opts ...ProgramOption) *Program { initialModel: model, msgs: make(chan Msg), errs: make(chan error, 1), - rendererDone: make(chan struct{}), } // Apply all options to the program. @@ -729,6 +725,9 @@ func (p *Program) eventLoop(model Model, cmds chan Cmd) (Model, error) { case err := <-p.errs: return model, err + case <-p.ticker.C: + go p.render(model) // render view + case msg := <-p.msgs: msg = p.translateInputEvent(msg) @@ -849,8 +848,6 @@ func (p *Program) eventLoop(model Model, cmds chan Cmd) (Model, error) { return model, nil case cmds <- cmd: // process command (if any) } - - p.render(model) // render view } } } @@ -860,6 +857,8 @@ func (p *Program) render(model Model) { if p.renderer != nil { p.renderer.render(model.View()) // send view to renderer } + _ = p.flush() + _ = p.renderer.flush(false) } func (p *Program) execSequenceMsg(msg sequenceMsg) { @@ -1360,30 +1359,12 @@ func (p *Program) startRenderer() { // Start the renderer. p.renderer.start() - go func() { - for { - select { - case <-p.rendererDone: - p.ticker.Stop() - return - - case <-p.ticker.C: - _ = p.flush() - _ = p.renderer.flush(false) - } - } - }() } // stopRenderer stops the renderer. // If kill is true, the renderer will be stopped immediately without flushing // the last frame. func (p *Program) stopRenderer(kill bool) { - // Stop the renderer before acquiring the mutex to avoid a deadlock. - p.once.Do(func() { - p.rendererDone <- struct{}{} - }) - if !kill { // flush locks the mutex _ = p.renderer.flush(true) diff --git a/testdata/TestClearMsg/bg_fg_cur_color.golden b/testdata/TestClearMsg/bg_fg_cur_color.golden index acc22fca31..d5f2e02dab 100644 --- a/testdata/TestClearMsg/bg_fg_cur_color.golden +++ b/testdata/TestClearMsg/bg_fg_cur_color.golden @@ -1 +1 @@ -[?25l[?2004h[=1;1u success[=0;1u [?25h[?2004l[?2026$p]10;?]11;?]12;? \ No newline at end of file +[?2026$p[?25l[?2004h[=1;1u[?u success]10;?]11;?]12;? success[=0;1u [?25h[?2004l \ No newline at end of file diff --git a/testdata/TestClearMsg/clear_screen.golden b/testdata/TestClearMsg/clear_screen.golden index b88a64b4d6..ab26a72b17 100644 --- a/testdata/TestClearMsg/clear_screen.golden +++ b/testdata/TestClearMsg/clear_screen.golden @@ -1 +1 @@ -[?25l [?2004h[=1;1usuccess[=0;1u [?25h[?2004l[?2026$p \ No newline at end of file +[?2026$p[?25l[?2004h[=1;1u[?u success success[=0;1u [?25h[?2004l \ No newline at end of file diff --git a/testdata/TestClearMsg/read_set_clipboard.golden b/testdata/TestClearMsg/read_set_clipboard.golden index a220e317eb..a18320f93e 100644 --- a/testdata/TestClearMsg/read_set_clipboard.golden +++ b/testdata/TestClearMsg/read_set_clipboard.golden @@ -1 +1 @@ -[?25l[?2004h[=1;1u success[=0;1u [?25h[?2004l[?2026$p]52;c;?]52;c;c3VjY2Vzcw== \ No newline at end of file +[?2026$p[?25l[?2004h[=1;1u[?u success]52;c;?]52;c;c3VjY2Vzcw== success[=0;1u [?25h[?2004l \ No newline at end of file diff --git a/testdata/TestViewModel/altscreen.golden b/testdata/TestViewModel/altscreen.golden index be0fd06567..ab26a72b17 100644 --- a/testdata/TestViewModel/altscreen.golden +++ b/testdata/TestViewModel/altscreen.golden @@ -1 +1 @@ -[?25l[?2004h[=1;1u success[=0;1u [?25h[?2004l[?2026$p \ No newline at end of file +[?2026$p[?25l[?2004h[=1;1u[?u success success[=0;1u [?25h[?2004l \ No newline at end of file diff --git a/testdata/TestViewModel/altscreen_autoexit.golden b/testdata/TestViewModel/altscreen_autoexit.golden index 2276d0e6ef..b932f8b40e 100644 --- a/testdata/TestViewModel/altscreen_autoexit.golden +++ b/testdata/TestViewModel/altscreen_autoexit.golden @@ -1 +1 @@ -[=0;1u[?1049h[?25l[?2004h[=1;1usuccess[=0;1u[?1049l[?25h[?2004l[?2026$p \ No newline at end of file +[?2026$p[?25l[?2004h[=1;1u[?u success[=0;1u[?1049h[?25l[=1;1u[?usuccess[=0;1u [?1049l[?25h[?2004l \ No newline at end of file diff --git a/testdata/TestViewModel/bg_set_color.golden b/testdata/TestViewModel/bg_set_color.golden index ded573f5be..8bcb9aa6ec 100644 --- a/testdata/TestViewModel/bg_set_color.golden +++ b/testdata/TestViewModel/bg_set_color.golden @@ -1 +1 @@ -[?25l[?2004h[=1;1u]11;#ffffff success[=0;1u [?25h[?2004l]111[?2026$p \ No newline at end of file +[?2026$p[?25l[?2004h[=1;1u[?u success]11;#ffffff success[=0;1u [?25h[?2004l]111 \ No newline at end of file diff --git a/testdata/TestViewModel/bp_stop_start.golden b/testdata/TestViewModel/bp_stop_start.golden index be0fd06567..ab26a72b17 100644 --- a/testdata/TestViewModel/bp_stop_start.golden +++ b/testdata/TestViewModel/bp_stop_start.golden @@ -1 +1 @@ -[?25l[?2004h[=1;1u success[=0;1u [?25h[?2004l[?2026$p \ No newline at end of file +[?2026$p[?25l[?2004h[=1;1u[?u success success[=0;1u [?25h[?2004l \ No newline at end of file diff --git a/testdata/TestViewModel/cursor_hide.golden b/testdata/TestViewModel/cursor_hide.golden index be0fd06567..ab26a72b17 100644 --- a/testdata/TestViewModel/cursor_hide.golden +++ b/testdata/TestViewModel/cursor_hide.golden @@ -1 +1 @@ -[?25l[?2004h[=1;1u success[=0;1u [?25h[?2004l[?2026$p \ No newline at end of file +[?2026$p[?25l[?2004h[=1;1u[?u success success[=0;1u [?25h[?2004l \ No newline at end of file diff --git a/testdata/TestViewModel/cursor_hideshow.golden b/testdata/TestViewModel/cursor_hideshow.golden index 1dde29559f..86a8a572d8 100644 --- a/testdata/TestViewModel/cursor_hideshow.golden +++ b/testdata/TestViewModel/cursor_hideshow.golden @@ -1 +1 @@ -[?2004h[=1;1u[1 q success [?25h[=0;1u[?2004l[?2026$p \ No newline at end of file +[?2026$p[?25l[?2004h[=1;1u[?u success[1 q success [?25h[=0;1u[?2004l \ No newline at end of file diff --git a/testdata/TestViewModel/kitty_stop_startreleases.golden b/testdata/TestViewModel/kitty_stop_startreleases.golden index d19733a816..4e94ce66b9 100644 --- a/testdata/TestViewModel/kitty_stop_startreleases.golden +++ b/testdata/TestViewModel/kitty_stop_startreleases.golden @@ -1 +1 @@ -[?25l[?2004h[=3;1u success[=0;1u [?25h[?2004l[?2026$p \ No newline at end of file +[?2026$p[?25l[?2004h[=1;1u[?u success[=3;1u[?u success[=0;1u [?25h[?2004l \ No newline at end of file diff --git a/testdata/TestViewModel/mouse_allmotion.golden b/testdata/TestViewModel/mouse_allmotion.golden index 3bd47585fa..bd428accb5 100644 --- a/testdata/TestViewModel/mouse_allmotion.golden +++ b/testdata/TestViewModel/mouse_allmotion.golden @@ -1 +1 @@ -[?25l[?2004h[?1003h[?1006h[=1;1u success[=0;1u [?25h[?2004l[?1002l[?1003l[?1006l[?2026$p \ No newline at end of file +[?2026$p[?25l[?2004h[=1;1u[?u success[?1003h[?1006h success[=0;1u [?25h[?2004l[?1002l[?1003l[?1006l \ No newline at end of file diff --git a/testdata/TestViewModel/mouse_cellmotion.golden b/testdata/TestViewModel/mouse_cellmotion.golden index 9067ee88d8..5b265b057c 100644 --- a/testdata/TestViewModel/mouse_cellmotion.golden +++ b/testdata/TestViewModel/mouse_cellmotion.golden @@ -1 +1 @@ -[?25l[?2004h[?1002h[?1006h[=1;1u success[=0;1u [?25h[?2004l[?1002l[?1003l[?1006l[?2026$p \ No newline at end of file +[?2026$p[?25l[?2004h[=1;1u[?u success[?1002h[?1006h success[=0;1u [?25h[?2004l[?1002l[?1003l[?1006l \ No newline at end of file diff --git a/testdata/TestViewModel/mouse_disable.golden b/testdata/TestViewModel/mouse_disable.golden index be0fd06567..ab26a72b17 100644 --- a/testdata/TestViewModel/mouse_disable.golden +++ b/testdata/TestViewModel/mouse_disable.golden @@ -1 +1 @@ -[?25l[?2004h[=1;1u success[=0;1u [?25h[?2004l[?2026$p \ No newline at end of file +[?2026$p[?25l[?2004h[=1;1u[?u success success[=0;1u [?25h[?2004l \ No newline at end of file