fix: don't close stdin

This allows programs to re-use stdin after the tea.Program has
finished.

Fixes #595.
This commit is contained in:
Christian Muehlhaeuser 2022-11-13 23:45:57 +01:00
parent e079831c31
commit 9c20a804d7
1 changed files with 2 additions and 4 deletions

6
tea.go
View File

@ -345,6 +345,7 @@ func (p *Program) Run() (Model, error) {
if err != nil { if err != nil {
return p.initialModel, err return p.initialModel, err
} }
defer f.Close() //nolint:errcheck
p.input = f p.input = f
case !p.startupOptions.has(withCustomInput): case !p.startupOptions.has(withCustomInput):
@ -364,11 +365,8 @@ func (p *Program) Run() (Model, error) {
if err != nil { if err != nil {
return p.initialModel, err return p.initialModel, err
} }
p.input = f
}
if f, ok := p.input.(io.ReadCloser); ok {
defer f.Close() //nolint:errcheck defer f.Close() //nolint:errcheck
p.input = f
} }
// Handle signals. // Handle signals.