fix: don't access output from outside renderer

This commit is contained in:
Christian Muehlhaeuser 2022-10-04 06:04:39 +02:00
parent 5d1a7264c5
commit 6b6bf6ab6d
2 changed files with 9 additions and 7 deletions

10
tea.go
View File

@ -257,17 +257,17 @@ func (p *Program) StartReturningModel() (Model, error) {
}()
}
// If no renderer is set use the standard one.
if p.renderer == nil {
p.renderer = newRenderer(p.output, p.startupOptions.has(withANSICompressor))
}
// Check if output is a TTY before entering raw mode, hiding the cursor and
// so on.
if err := p.initTerminal(); err != nil {
return p.initialModel, err
}
// If no renderer is set use the standard one.
if p.renderer == nil {
p.renderer = newRenderer(p.output, p.startupOptions.has(withANSICompressor))
}
// Honor program startup options.
if p.startupOptions&withAltScreen != 0 {
p.renderer.enterAltScreen()

6
tty.go
View File

@ -21,14 +21,16 @@ func (p *Program) initTerminal() error {
}
}
p.output.HideCursor()
p.renderer.hideCursor()
return nil
}
// restoreTerminalState restores the terminal to the state prior to running the
// Bubble Tea program.
func (p *Program) restoreTerminalState() error {
p.output.ShowCursor()
if p.renderer != nil {
p.renderer.showCursor()
}
if p.console != nil {
err := p.console.Reset()