mirror of
https://github.com/taigrr/bubbletea.git
synced 2026-04-02 02:59:09 -07:00
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:
32
tea.go
32
tea.go
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user