Compare commits
1 commit
main
...
v2-render-
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
50d023dc52 |
14 changed files with 18 additions and 37 deletions
29
tea.go
29
tea.go
|
|
@ -517,9 +517,6 @@ type Program struct {
|
||||||
// once is used to stop the renderer.
|
// once is used to stop the renderer.
|
||||||
once sync.Once
|
once sync.Once
|
||||||
|
|
||||||
// rendererDone is used to stop the renderer.
|
|
||||||
rendererDone chan struct{}
|
|
||||||
|
|
||||||
// Initial window size. Mainly used for testing.
|
// Initial window size. Mainly used for testing.
|
||||||
width, height int
|
width, height int
|
||||||
|
|
||||||
|
|
@ -577,7 +574,6 @@ func NewProgram(model Model, opts ...ProgramOption) *Program {
|
||||||
initialModel: model,
|
initialModel: model,
|
||||||
msgs: make(chan Msg),
|
msgs: make(chan Msg),
|
||||||
errs: make(chan error, 1),
|
errs: make(chan error, 1),
|
||||||
rendererDone: make(chan struct{}),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Apply all options to the program.
|
// 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:
|
case err := <-p.errs:
|
||||||
return model, err
|
return model, err
|
||||||
|
|
||||||
|
case <-p.ticker.C:
|
||||||
|
go p.render(model) // render view
|
||||||
|
|
||||||
case msg := <-p.msgs:
|
case msg := <-p.msgs:
|
||||||
msg = p.translateInputEvent(msg)
|
msg = p.translateInputEvent(msg)
|
||||||
|
|
||||||
|
|
@ -849,8 +848,6 @@ func (p *Program) eventLoop(model Model, cmds chan Cmd) (Model, error) {
|
||||||
return model, nil
|
return model, nil
|
||||||
case cmds <- cmd: // process command (if any)
|
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 {
|
if p.renderer != nil {
|
||||||
p.renderer.render(model.View()) // send view to renderer
|
p.renderer.render(model.View()) // send view to renderer
|
||||||
}
|
}
|
||||||
|
_ = p.flush()
|
||||||
|
_ = p.renderer.flush(false)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Program) execSequenceMsg(msg sequenceMsg) {
|
func (p *Program) execSequenceMsg(msg sequenceMsg) {
|
||||||
|
|
@ -1360,30 +1359,12 @@ func (p *Program) startRenderer() {
|
||||||
|
|
||||||
// Start the renderer.
|
// Start the renderer.
|
||||||
p.renderer.start()
|
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.
|
// stopRenderer stops the renderer.
|
||||||
// If kill is true, the renderer will be stopped immediately without flushing
|
// If kill is true, the renderer will be stopped immediately without flushing
|
||||||
// the last frame.
|
// the last frame.
|
||||||
func (p *Program) stopRenderer(kill bool) {
|
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 {
|
if !kill {
|
||||||
// flush locks the mutex
|
// flush locks the mutex
|
||||||
_ = p.renderer.flush(true)
|
_ = p.renderer.flush(true)
|
||||||
|
|
|
||||||
2
testdata/TestClearMsg/bg_fg_cur_color.golden
vendored
2
testdata/TestClearMsg/bg_fg_cur_color.golden
vendored
|
|
@ -1 +1 @@
|
||||||
[?25l[?2004h[=1;1u
[Jsuccess[=0;1u
[J[?25h[?2004l[?2026$p]10;?]11;?]12;?
|
[?2026$p[?25l[?2004h[=1;1u[?u
[Jsuccess]10;?]11;?]12;?
[Jsuccess[=0;1u
[J[?25h[?2004l
|
||||||
2
testdata/TestClearMsg/clear_screen.golden
vendored
2
testdata/TestClearMsg/clear_screen.golden
vendored
|
|
@ -1 +1 @@
|
||||||
[?25l
[?2004h[=1;1u[Jsuccess[=0;1u
[J[?25h[?2004l[?2026$p
|
[?2026$p[?25l[?2004h[=1;1u[?u
[Jsuccess
[Jsuccess[=0;1u
[J[?25h[?2004l
|
||||||
|
|
@ -1 +1 @@
|
||||||
[?25l[?2004h[=1;1u
[Jsuccess[=0;1u
[J[?25h[?2004l[?2026$p]52;c;?]52;c;c3VjY2Vzcw==
|
[?2026$p[?25l[?2004h[=1;1u[?u
[Jsuccess]52;c;?]52;c;c3VjY2Vzcw==
[Jsuccess[=0;1u
[J[?25h[?2004l
|
||||||
2
testdata/TestViewModel/altscreen.golden
vendored
2
testdata/TestViewModel/altscreen.golden
vendored
|
|
@ -1 +1 @@
|
||||||
[?25l[?2004h[=1;1u
[Jsuccess[=0;1u
[J[?25h[?2004l[?2026$p
|
[?2026$p[?25l[?2004h[=1;1u[?u
[Jsuccess
[Jsuccess[=0;1u
[J[?25h[?2004l
|
||||||
|
|
@ -1 +1 @@
|
||||||
[=0;1u[?1049h[?25l[?2004h[=1;1u[H[2Jsuccess[=0;1u[?1049l[?25h[?2004l[?2026$p
|
[?2026$p[?25l[?2004h[=1;1u[?u
[Jsuccess[=0;1u[?1049h[?25l[=1;1u[?u[H[2J[Jsuccess[=0;1u
[24d[?1049l[?25h[?2004l
|
||||||
2
testdata/TestViewModel/bg_set_color.golden
vendored
2
testdata/TestViewModel/bg_set_color.golden
vendored
|
|
@ -1 +1 @@
|
||||||
[?25l[?2004h[=1;1u]11;#ffffff
[Jsuccess[=0;1u
[J[?25h[?2004l]111[?2026$p
|
[?2026$p[?25l[?2004h[=1;1u[?u
[Jsuccess]11;#ffffff
[Jsuccess[=0;1u
[J[?25h[?2004l]111
|
||||||
2
testdata/TestViewModel/bp_stop_start.golden
vendored
2
testdata/TestViewModel/bp_stop_start.golden
vendored
|
|
@ -1 +1 @@
|
||||||
[?25l[?2004h[=1;1u
[Jsuccess[=0;1u
[J[?25h[?2004l[?2026$p
|
[?2026$p[?25l[?2004h[=1;1u[?u
[Jsuccess
[Jsuccess[=0;1u
[J[?25h[?2004l
|
||||||
2
testdata/TestViewModel/cursor_hide.golden
vendored
2
testdata/TestViewModel/cursor_hide.golden
vendored
|
|
@ -1 +1 @@
|
||||||
[?25l[?2004h[=1;1u
[Jsuccess[=0;1u
[J[?25h[?2004l[?2026$p
|
[?2026$p[?25l[?2004h[=1;1u[?u
[Jsuccess
[Jsuccess[=0;1u
[J[?25h[?2004l
|
||||||
|
|
@ -1 +1 @@
|
||||||
[?2004h[=1;1u[1 q
[Jsuccess
[?25h[=0;1u[J[?2004l[?2026$p
|
[?2026$p[?25l[?2004h[=1;1u[?u
[Jsuccess[1 q
[Jsuccess
[?25h[=0;1u[J[?2004l
|
||||||
|
|
@ -1 +1 @@
|
||||||
[?25l[?2004h[=3;1u
[Jsuccess[=0;1u
[J[?25h[?2004l[?2026$p
|
[?2026$p[?25l[?2004h[=1;1u[?u
[Jsuccess[=3;1u[?u
[Jsuccess[=0;1u
[J[?25h[?2004l
|
||||||
|
|
@ -1 +1 @@
|
||||||
[?25l[?2004h[?1003h[?1006h[=1;1u
[Jsuccess[=0;1u
[J[?25h[?2004l[?1002l[?1003l[?1006l[?2026$p
|
[?2026$p[?25l[?2004h[=1;1u[?u
[Jsuccess[?1003h[?1006h
[Jsuccess[=0;1u
[J[?25h[?2004l[?1002l[?1003l[?1006l
|
||||||
|
|
@ -1 +1 @@
|
||||||
[?25l[?2004h[?1002h[?1006h[=1;1u
[Jsuccess[=0;1u
[J[?25h[?2004l[?1002l[?1003l[?1006l[?2026$p
|
[?2026$p[?25l[?2004h[=1;1u[?u
[Jsuccess[?1002h[?1006h
[Jsuccess[=0;1u
[J[?25h[?2004l[?1002l[?1003l[?1006l
|
||||||
2
testdata/TestViewModel/mouse_disable.golden
vendored
2
testdata/TestViewModel/mouse_disable.golden
vendored
|
|
@ -1 +1 @@
|
||||||
[?25l[?2004h[=1;1u
[Jsuccess[=0;1u
[J[?25h[?2004l[?2026$p
|
[?2026$p[?25l[?2004h[=1;1u[?u
[Jsuccess
[Jsuccess[=0;1u
[J[?25h[?2004l
|
||||||
Loading…
Reference in a new issue