From fbb00cc71eaad80be9cc3888eebb9415e47ba722 Mon Sep 17 00:00:00 2001 From: Christian Muehlhaeuser Date: Fri, 7 Oct 2022 23:29:01 +0200 Subject: [PATCH] fix: close input on shutdown whenever possible --- tea.go | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/tea.go b/tea.go index c822402..b9fc96b 100644 --- a/tea.go +++ b/tea.go @@ -351,9 +351,6 @@ func (p *Program) StartReturningModel() (Model, error) { if err != nil { return p.initialModel, err } - - defer f.Close() //nolint:errcheck - p.input = f case !p.startupOptions.has(withCustomInput): @@ -373,12 +370,13 @@ func (p *Program) StartReturningModel() (Model, error) { if err != nil { return p.initialModel, err } - - defer f.Close() //nolint:errcheck - p.input = f } + if f, ok := p.input.(io.ReadCloser); ok { + defer f.Close() //nolint:errcheck + } + // Handle signals. if !p.startupOptions.has(withoutSignalHandler) { handlers.add(p.handleSignals())