fix(regression): auto-open a TTY when stdin is not a TTY (#746)

The regression was introduced in precisely this revision:
fcc805f3da

Closes #745.
This commit is contained in:
Christian Rocha
2023-05-24 12:31:00 -04:00
committed by GitHub
parent d1a16bd883
commit c267762438

32
tea.go
View File

@@ -392,20 +392,12 @@ func (p *Program) Run() (Model, error) {
case defaultInput:
p.input = os.Stdin
case ttyInput:
// Open a new TTY, by request
f, err := openInputTTY()
if err != nil {
return p.initialModel, err
}
defer f.Close() //nolint:errcheck
p.input = f
case customInput:
// 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.
// The user has not set a custom input, so we need to check whether or
// not standard input is a terminal. If it's not, we open a new TTY for
// input. This will allow things to "just work" in cases where data was
// piped in or redirected to the application.
//
// To disable input entirely pass nil to the [WithInput] program option.
f, isFile := p.input.(*os.File)
if !isFile {
break
@@ -420,6 +412,18 @@ func (p *Program) Run() (Model, error) {
}
defer f.Close() //nolint:errcheck
p.input = f
case ttyInput:
// Open a new TTY, by request
f, err := openInputTTY()
if err != nil {
return p.initialModel, err
}
defer f.Close() //nolint:errcheck
p.input = f
case customInput:
// (There is nothing extra to do.)
}
// Handle signals.