Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 5 additions & 24 deletions tea.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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
}
}
}
Expand All @@ -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) {
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion testdata/TestClearMsg/bg_fg_cur_color.golden
Original file line number Diff line number Diff line change
@@ -1 +1 @@
[?25l[?2004h[=1;1usuccess[=0;1u[?25h[?2004l[?2026$p]10;?]11;?]12;?
[?2026$p[?25l[?2004h[=1;1u[?usuccess]10;?]11;?]12;?success[=0;1u[?25h[?2004l
Expand Down
2 changes: 1 addition & 1 deletion testdata/TestClearMsg/clear_screen.golden
Original file line number Diff line number Diff line change
@@ -1 +1 @@
[?25l[?2004h[=1;1usuccess[=0;1u[?25h[?2004l[?2026$p
[?2026$p[?25l[?2004h[=1;1u[?usuccesssuccess[=0;1u[?25h[?2004l
Expand Down
2 changes: 1 addition & 1 deletion testdata/TestClearMsg/read_set_clipboard.golden
Original file line number Diff line number Diff line change
@@ -1 +1 @@
[?25l[?2004h[=1;1usuccess[=0;1u[?25h[?2004l[?2026$p]52;c;?]52;c;c3VjY2Vzcw==
[?2026$p[?25l[?2004h[=1;1u[?usuccess]52;c;?]52;c;c3VjY2Vzcw==success[=0;1u[?25h[?2004l
Expand Down
2 changes: 1 addition & 1 deletion testdata/TestViewModel/altscreen.golden
Original file line number Diff line number Diff line change
@@ -1 +1 @@
[?25l[?2004h[=1;1usuccess[=0;1u[?25h[?2004l[?2026$p
[?2026$p[?25l[?2004h[=1;1u[?usuccesssuccess[=0;1u[?25h[?2004l
Expand Down
2 changes: 1 addition & 1 deletion testdata/TestViewModel/altscreen_autoexit.golden
Original file line number Diff line number Diff line change
@@ -1 +1 @@
[=0;1u[?1049h[?25l[?2004h[=1;1usuccess[=0;1u[?1049l[?25h[?2004l[?2026$p
[?2026$p[?25l[?2004h[=1;1u[?usuccess[=0;1u[?1049h[?25l[=1;1u[?usuccess[=0;1u[?1049l[?25h[?2004l
Expand Down
2 changes: 1 addition & 1 deletion testdata/TestViewModel/bg_set_color.golden
Original file line number Diff line number Diff line change
@@ -1 +1 @@
[?25l[?2004h[=1;1u]11;#ffffffsuccess[=0;1u[?25h[?2004l]111[?2026$p
[?2026$p[?25l[?2004h[=1;1u[?usuccess]11;#ffffffsuccess[=0;1u[?25h[?2004l]111
Expand Down
2 changes: 1 addition & 1 deletion testdata/TestViewModel/bp_stop_start.golden
Original file line number Diff line number Diff line change
@@ -1 +1 @@
[?25l[?2004h[=1;1usuccess[=0;1u[?25h[?2004l[?2026$p
[?2026$p[?25l[?2004h[=1;1u[?usuccesssuccess[=0;1u[?25h[?2004l
Expand Down
2 changes: 1 addition & 1 deletion testdata/TestViewModel/cursor_hide.golden
Original file line number Diff line number Diff line change
@@ -1 +1 @@
[?25l[?2004h[=1;1usuccess[=0;1u[?25h[?2004l[?2026$p
[?2026$p[?25l[?2004h[=1;1u[?usuccesssuccess[=0;1u[?25h[?2004l
Expand Down
2 changes: 1 addition & 1 deletion testdata/TestViewModel/cursor_hideshow.golden
Original file line number Diff line number Diff line change
@@ -1 +1 @@
[?2004h[=1;1u[1 qsuccess[?25h[=0;1u[?2004l[?2026$p
[?2026$p[?25l[?2004h[=1;1u[?usuccess[1 qsuccess[?25h[=0;1u[?2004l
Expand Down
2 changes: 1 addition & 1 deletion testdata/TestViewModel/kitty_stop_startreleases.golden
Original file line number Diff line number Diff line change
@@ -1 +1 @@
[?25l[?2004h[=3;1usuccess[=0;1u[?25h[?2004l[?2026$p
[?2026$p[?25l[?2004h[=1;1u[?usuccess[=3;1u[?usuccess[=0;1u[?25h[?2004l
Expand Down
2 changes: 1 addition & 1 deletion testdata/TestViewModel/mouse_allmotion.golden
Original file line number Diff line number Diff line change
@@ -1 +1 @@
[?25l[?2004h[?1003h[?1006h[=1;1usuccess[=0;1u[?25h[?2004l[?1002l[?1003l[?1006l[?2026$p
[?2026$p[?25l[?2004h[=1;1u[?usuccess[?1003h[?1006hsuccess[=0;1u[?25h[?2004l[?1002l[?1003l[?1006l
Expand Down
2 changes: 1 addition & 1 deletion testdata/TestViewModel/mouse_cellmotion.golden
Original file line number Diff line number Diff line change
@@ -1 +1 @@
[?25l[?2004h[?1002h[?1006h[=1;1usuccess[=0;1u[?25h[?2004l[?1002l[?1003l[?1006l[?2026$p
[?2026$p[?25l[?2004h[=1;1u[?usuccess[?1002h[?1006hsuccess[=0;1u[?25h[?2004l[?1002l[?1003l[?1006l
Expand Down
2 changes: 1 addition & 1 deletion testdata/TestViewModel/mouse_disable.golden
Original file line number Diff line number Diff line change
@@ -1 +1 @@
[?25l[?2004h[=1;1usuccess[=0;1u[?25h[?2004l[?2026$p
[?2026$p[?25l[?2004h[=1;1u[?usuccesssuccess[=0;1u[?25h[?2004l
Expand Down
Loading