Skip to content

Commit

Permalink
fix(regression): auto-open a TTY when stdin is not a TTY (#746)
Browse files Browse the repository at this point in the history
The regression was introduced in precisely this revision:
fcc805f

Closes #745.
  • Loading branch information
meowgorithm committed May 24, 2023
1 parent d1a16bd commit c267762
Showing 1 changed file with 18 additions and 14 deletions.
32 changes: 18 additions & 14 deletions tea.go
Expand Up @@ -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
Expand All @@ -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.
Expand Down

0 comments on commit c267762

Please sign in to comment.