Skip to content
Myr

fix: stop renderer before launching a child process.

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Stops the renderer before starting a child process, which prevents the repaint race condition that writes to non-altscreen.

authored by Christian Muehlhaeuser · committed by Christian Muehlhaeuser · parent 90c9124 · Browse files · 2 files+17 added−8 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+17 added−8 removed

  • other:+17 added−8 removed

2 files+17 added−8 removed

modified:standard_renderer.go+10 added-8 removed
56 unmodified lines
57func newRenderer(out *termenv.Output, useANSICompressor bool) renderer {58 r := &standardRenderer{59 out: out,60 mtx: &sync.Mutex{},61 done: make(chan struct{}),62 framerate: defaultFramerate,63 useANSICompressor: useANSICompressor,64 queuedMessageLines: []string{},65 }
6 unmodified lines
72// start starts the renderer.73func (r *standardRenderer) start() {74 if r.ticker == nil {75 r.ticker = time.NewTicker(r.framerate)76 } else {77 // If the ticker already exists, it has been stopped and we need to78 // reset it.79 r.ticker.Reset(r.framerate)80 }8182 // Since the renderer can be restarted after a stop, we need to reset83 // the done channel and its corresponding sync.Once.84 r.once = sync.Once{}80 r.done = make(chan struct{})8586 go r.listen()87}88
6 unmodified lines
95 defer r.mtx.Unlock()9697 r.out.ClearLine()98 r.once.Do(func() {95 close(r.done)99 r.done <- struct{}{}100 })101102 if r.useANSICompressor {103 if w, ok := r.out.TTY().(io.WriteCloser); ok {
8 unmodified lines
112 defer r.mtx.Unlock()113114 r.out.ClearLine()115 r.once.Do(func() {112 close(r.done)116 r.done <- struct{}{}117 })118}119120// listen waits for ticks on the ticker, or a signal to stop the renderer.121func (r *standardRenderer) listen() {122 for {123 select {120 case <-r.ticker.C:121 if r.ticker != nil {122 r.flush()123 }124 case <-r.done:125 r.ticker.Stop()126 r.ticker = nil126 return127128 case <-r.ticker.C:129 r.flush()130 }131 }132}133
524 unmodified lines
modified:tea.go+7 added
565 unmodified lines
566 p.ignoreSignals = true567 p.cancelReader.Cancel()568 p.waitForReadLoop()569570 if p.renderer != nil {571 p.renderer.stop()572 }573574 p.altScreenWasActive = p.renderer.altScreen()575 return p.restoreTerminalState()576}577
15 unmodified lines
593 } else {594 // entering alt screen already causes a repaint.595 go p.Send(repaintMsg{})596 }597 if p.renderer != nil {598 p.renderer.start()599 }600601 // If the output is a terminal, it may have been resized while another602 // process was at the foreground, in which case we may not have received603 // SIGWINCH. Detect any size change now and propagate the new size as
48 unmodified lines