fix: restore terminal state on Run error paths (#1854)
Co-authored-by: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
This commit is contained in:
parent
56a2fe7fed
commit
12b7b4d0eb
1 changed files with 6 additions and 0 deletions
6
tea.go
6
tea.go
|
|
@ -1109,6 +1109,10 @@ func (p *Program) Run() (returnModel Model, returnErr error) {
|
|||
// Check if output is a TTY before entering raw mode, hiding the cursor and
|
||||
// so on.
|
||||
if err := p.initTerminal(); err != nil {
|
||||
// The input may already be in raw mode at this point (on Windows it
|
||||
// is made raw before the output console-mode setup), so restore the
|
||||
// terminal before returning the error.
|
||||
_ = p.restoreTerminalState()
|
||||
return p.initialModel, err
|
||||
}
|
||||
|
||||
|
|
@ -1118,6 +1122,7 @@ func (p *Program) Run() (returnModel Model, returnErr error) {
|
|||
// Set the initial size of the terminal.
|
||||
w, h, err := term.GetSize(p.ttyOutput.Fd())
|
||||
if err != nil {
|
||||
_ = p.restoreTerminalState()
|
||||
return p.initialModel, fmt.Errorf("bubbletea: error getting terminal size: %w", err)
|
||||
}
|
||||
|
||||
|
|
@ -1174,6 +1179,7 @@ func (p *Program) Run() (returnModel Model, returnErr error) {
|
|||
model := p.initialModel
|
||||
if p.input != nil {
|
||||
if err := p.initInputReader(false); err != nil {
|
||||
_ = p.restoreTerminalState()
|
||||
return model, err
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue