From 30fd7a8f2051c8690784ad679800980ef8e84725 Mon Sep 17 00:00:00 2001 From: Christian Rocha Date: Thu, 29 Jul 2021 17:01:38 -0400 Subject: [PATCH] Better logic in input checks --- tea.go | 36 +++++++++++++++++++++--------------- 1 file changed, 21 insertions(+), 15 deletions(-) diff --git a/tea.go b/tea.go index 37e9082..82bacbc 100644 --- a/tea.go +++ b/tea.go @@ -272,28 +272,34 @@ func (p *Program) Start() error { p.outputIsTTY = isatty.IsTerminal(f.Fd()) } - // Open a new TTY, by request - if p.startupOptions.has(withInputTTY) { + switch { + case p.startupOptions.has(withInputTTY): + // Open a new TTY, by request f, err := openInputTTY() if err != nil { return err } p.input = f - } - // If input is not a terminal, and the user hasn't set a custom input, open - // a TTY so we can capture input as normal. This will allow things to "just - // work" in cases where data was piped or redirected into this application. - if f, ok := p.input.(*os.File); ok { - inputIsTTY := isatty.IsTerminal(f.Fd()) - - if !inputIsTTY && !p.startupOptions.has(withCustomInput) { - f, err := openInputTTY() - if err != nil { - return err - } - p.input = f + case !p.startupOptions.has(withCustomInput): + // If the user hasn't set a custom input, and input's not a terminal, + // open a TTY so we can capture input as normal. This will allow things + // to "just work" in cases where data was piped or redirected into this + // application. + f, isFile := p.input.(*os.File) + if !isFile { + break } + + if isatty.IsTerminal(f.Fd()) { + break + } + + f, err := openInputTTY() + if err != nil { + return err + } + p.input = f } // Listen for SIGINT. Note that in most cases ^C will not send an